在WordPress支持通過Aaron Forgue答案是3歲,但會很有趣。我不得不改變$wpdb->query()
,使其工作:
global $wpdb;
$profile_id = $_POST['prof_id'];
$username = $_POST['log_name'];
$password = $_POST['wachtwoord'];
$md5password = wp_hash_password($password);
// You may want to use $wpdb->prepare() here. As it stands, malicous code could be passed in via $_POST['prof_id'] or $_POST['log_name']
$wpdb->query($wpdb->prepare(
"
UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d
",
$md5password,
$profile_id
));
// Here is the magic:
wp_cache_delete($profile_id, 'users');
wp_cache_delete($username, 'userlogins'); // This might be an issue for how you are doing it. Presumably you'd need to run this for the ORIGINAL user login name, not the new one.
wp_logout();
wp_signon(array('user_login' => $username, 'user_password' => $password));
現金去這個插件上面的絕招:http://wordpress.org/extend/plugins/change-password-e-mail/
正如Robahas提到,確保該代碼運行之前頭是發送,否則wp_signon()
將無法正常工作,用戶無論如何都將被註銷。
來源
2015-03-11 13:15:52
Wim
這是不可能的,你不能玩當前的cookie隨着更改密碼,因爲你的網頁將在更改密碼後刷新 –
我認爲你不知道wordpress的功能wp_update_user – Mayur
如果你知道比關閉話題更好。 –