Viruthagiri

Untitled

Apr 3rd, 2012
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Change User Password
  2. function change_user_password($currentPass, $newPass1, $newPass2) {
  3.  
  4.     require ( ABSPATH . WPINC . '/registration.php' );
  5.    
  6.     global $uriData;
  7.     $uriData->author = wp_get_current_user();
  8.     $oldPass = $uriData->author->user_pass;
  9.  
  10.     //Strip any tags then may have been put into the array
  11.     $currentPass_stripped = strip_tags($currentPass);
  12.     $newPass1_stripped = strip_tags($newPass1);
  13.     $newPass2_stripped = strip_tags($newPass2);
  14.    
  15.     // Validate the Form Data
  16.     if (isEmptyString($currentPass_stripped)) return new WP_Error('no_old_password_entered','Enter your Current Password');
  17.     if (isEmptyString($newPass1_stripped)) return new WP_Error('no_new_password_entered','Enter a new Password');
  18.     if (isEmptyString($newPass2_stripped)) return new WP_Error('no_new_password_confirm_entered','Confirm your new Password');
  19.     if ($newPass1_stripped != $newPass2_stripped) return new WP_Error('new_pass_no_match','New Password and Confirm Password must be the same');
  20.     if (!wp_check_password($currentPass_stripped, $oldPass)) return new WP_Error('current_pass_incorrect','Current Password is Incorrect');
  21.    
  22.     // Change User's Password
  23.     wp_update_user( array(
  24.         'ID' => $uriData->author->ID,
  25.         'user_pass' => $newPass1_stripped
  26.         )
  27.     );
  28.    
  29.     // Update the Password Cookie
  30.     $cookie_info = wp_get_cookie_login();
  31.     $login = $cookie_info['login'];
  32.     wp_clearcookie();
  33.     wp_setcookie($uriData->author->user_login, $newPass1);
  34.    
  35.     $user = wp_get_current_user();
  36.    
  37.     // Add a flag for Messaging the user that they have successfully changed their password
  38.     update_usermeta($user->ID, 'changed_password_my_account', 'yes');
  39.  
  40.     // Redirect the User to My Account
  41.     return $message = 'You have successfully changed your password' ;
  42.    
  43. }
RAW Paste Data