使用wp\\u set\\u password()更新用户密码,然后使用wp\\u signon()重新登录用户。
正如其他用户所建议的那样,wp\\u signon将为您创建身份验证cookie,但方式要简化得多。
function create_new_password_for_user($new_password){
//Get the current user\'s details, while they\'re still signed in, in this scope.
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
$users_login = $current_user->user_email;
//set their new password (this will trigger the logout)
wp_set_password($new_password, $current_user_id);
//setup the data to be passed on to wp_signon
$user_data = array(
\'user_login\' => $users_login,
\'user_password\' => $new_password,
\'remember\' => false
);
// Sign them back in.
$result = wp_signon( $user_data );
if(is_wp_error($result)){
//do something with an error, if there is one.
}else{
//do something with the successful change.
}
}