2013-10-16 44 views
1

我在前端更改密碼,我使用wp_user_update功能,但是當用戶更改密碼時它已經註銷。問題是,我的老餅乾沒有更新,那麼如何在不更新日誌密碼out.have任何想法?..當密碼更新的用戶註銷時的Wordpress

global $wpdb, $current_user; 

$user_id = $current_user->ID; 
wp_update_user(array('ID'=>$user_id,'user_pass'=>$_POST['user_pass'])); 
+0

這是不可能的,你不能玩當前的cookie隨着更改密碼,因爲你的網頁將在更改密碼後刷新 –

+0

我認爲你不知道wordpress的功能wp_update_user – Mayur

+0

如果你知道比關閉話題更好。 –

回答

1

在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()將無法​​正常工作,用戶無論如何都將被註銷。

相關問題