WordPress笔记20151219

这篇博客介绍了如何在WordPress中创建用户,设置当前用户,并进行账号密码的正确性校验。还讨论了与user_meta相关的重要函数,如add_user_meta、delete_user_meta等,强调了这些函数在处理多值meta_key时的注意事项。
摘要由CSDN通过智能技术生成

创建用户

使用wp_insert_user( $userdata )函数创建用户,其中user_login和user_pass是必须项。

可能的错误包括以下几种:

  • invalid_user_id
  • empty_user_login
  • user_login_too_long
  • existing_user_login
  • invalid_username
  • user_nicename_too_long
  • existing_user_email

判断创建用户是否成功则只需要判断if( !is_wp_error($user_id) )

设置当前用户

使用wp_set_current_user($id, $name = '')函数设置当前用户,然后就可以通过get_currentuserinfo()获取信息。
但是注意,这是一个使用方便但不安全的接口:

Some WordPress functionality is based on the current user and not based on
the signed in user. Therefore, it opens the ability to edit and perform
actions on users who aren’t signed in.

校验账号密码是否正确

使用wp_authenticate_username_password($user, $username, $password)函数校验账号密码是否正确,如果该

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值