WordPress change user password without login again
You may want to change the user password in your plugin/theme. But you found once you set users’ password with what they entered, the user will be redirected to wp_login.php and ask the user to log in again, why? Here tell you how to deal with this.
The reason is that you use API of wp_set_password to set users’ passwords, the API will clear users’ cookies so it will ask the user to log in again.
The correct API you use should be wp_update_user, the API let you update users’ password but without a clear cookie, so it means need not to login again and won’t be redirected to wp_login.php .
wp_update_user( array('ID' => $user_id, 'user_pass' => $password) );
Post a Comment