WordPress 使用 PHP 更新用户密码
我有一个使用 Wordpress 进行身份验证的网络应用程序。我那里有一个帐户选项页面。打开后,它包含密码更新部分。我将其发布到我的 PHP 脚本并运行此代码:
wp_update_user(array('ID' => getUserIDWP(), 'user_pass' => $_POST['newpass']))
它记录我退出了当前的 Wordpress 会话,但是当我尝试使用我在其中指定的密码重新登录时,它说我输入了错误的密码。如果有人能够阐明这个主题,我将不胜感激。
注意:getUserIDWP()
函数是 $current_user->ID;
和其他相关内容的别名。
I have a webapp that uses Wordpress for it's authentication. I have an Account options page there. When opened, it contains a password update section. I POST this to my PHP script and run this code:
wp_update_user(array('ID' => getUserIDWP(), 'user_pass' => $_POST['newpass']))
It logs me out of my current Wordpress session, but when I try to log back in with the password I specified there, it says that I entered an incorrect password. I'd appreciate if someone could shed some light on this subject.
Note: the getUserIDWP()
function is an alias for $current_user->ID;
and the other related stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试下面的代码,它不会在密码更改后将您注销,并且它也适用于 Ajax。另外,之后无需重置 cookie/会话。
Try below code, it won't log you out after password change and it works with Ajax too. Also, no need to reset cookies/session after it.
它对我使用
update_user_meta
和wp_update_user
更新'user_pass'
有效:It worked for me to update
'user_pass'
using bothupdate_user_meta
andwp_update_user
:我知道已经晚了但是...
我遇到了类似的问题,结果发现 usermeta 表中有一个名为 user_pass 的条目。我删除了该条目,然后可以再次登录。
也许这会对某人有所帮助——我花了最后一个小时试图找出我做错了什么。
I know it's late but...
I had a similar problem and it turns out there was an entry in the usermeta table called user_pass. I deleted that entry and I could log in again.
Maybe this will help somebody - I spent the last hour trying to figure out what I did wrong.
试试这个
try this one