WordPress Reset Password of login user


Reset password of a login user. While resetting a login user password remember you must use the function
wp_clear_auth_cookie();
wp_set_auth_cookie();

See the below example:

  
     <?php 
     global $userdata;

     if (isset($_POST['submit_resetpass'])) {
         $error = "";
         $success = "";
         $new_password = trim($_POST['new_password']);
         $retype_password = trim($_POST['retype_new_password']);
         $current_user_id = $userdata->ID;
         if( $new_password == $retype_password ){
           wp_set_password($new_password, $current_user_id);
           wp_clear_auth_cookie();
           wp_set_auth_cookie($current_user_id);
           $success = "Password successfully reset.";
        }else{
           $error = "Password not matched, please try again.";
        }   
    }
   ?>
  
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s