PHP的WordPress的密码更改-登出我! [英] php wordpress password change - logging me out!

查看:74
本文介绍了PHP的WordPress的密码更改-登出我!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建自己的简单wordpress密码更改脚本(确实是基于插件)-密码已成功更改-但更改完成后却注销了我!下面是使用的代码.谁能看到我被注销的地方以及如何防止它退出?谢谢!

I'm trying to build a simple wordpress password change script of my own (well, based on a plugin really) - the password is successfully changed - but it logs me out after the change completes! Below is the code used. Can anyone see where I'm being logged out and how to prevent it? Thanks!

$update = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET `user_pass` = %s WHERE `ID` = %d",array(wp_hash_password($_POST['admin_pass1']),$user_ID)));

if(!is_wp_error($update))
{
    wp_cache_delete($user_ID,'users');
    wp_cache_delete($user->user_login,'userlogins');
    wp_logout();
    if (wp_signon(array('user_login'=>$user->user_login,'user_password'=>$_POST['admin_pass1']),false)):
        wp_redirect(admin_url());
    endif;
    ob_start();
}

推荐答案

重置密码后,您必须设置/重置cookie(

After resetting password you have to set/reset cookies (http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie)
like this

$update = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET `user_pass` = %s WHERE `ID` = %d",array(wp_hash_password($_POST['admin_pass1']),$user_ID)));

if(!is_wp_error($update))
{
    wp_cache_delete($user_ID,'users');
    wp_cache_delete($user->user_login,'userlogins');
    wp_logout();
    if (wp_signon(array('user_login'=>$user->user_login,'user_password'=>$_POST['admin_pass1']),false)):
        wp_redirect(admin_url());
    endif;
    ob_start();
}else{
    wp_set_auth_cookie( $current_user_id, true);
}

要重置密码,由于与其他应用程序/插件集成,最好使用wp_check_password和wp_set_password之类的wordpress函数.

To reset the password you'd better use wordpress functions like wp_check_password and wp_set_password because of integration with other applications/plugins.

这篇关于PHP的WordPress的密码更改-登出我!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆