
Untitled
// Change User Password
function change_user_password($currentPass, $newPass1, $newPass2) {
require ( ABSPATH . WPINC . '/registration.php' );
global $uriData;
$uriData->author = wp_get_current_user();
$oldPass = $uriData->author->user_pass;
//Strip any tags then may have been put into the array
$currentPass_stripped = strip_tags($currentPass);
$newPass1_stripped = strip_tags($newPass1);
$newPass2_stripped = strip_tags($newPass2);
// Validate the Form Data
if (isEmptyString($currentPass_stripped)) return new WP_Error('no_old_password_entered','Enter your Current Password');
if (isEmptyString($newPass1_stripped)) return new WP_Error('no_new_password_entered','Enter a new Password');
if (isEmptyString($newPass2_stripped)) return new WP_Error('no_new_password_confirm_entered','Confirm your new Password');
if ($newPass1_stripped != $newPass2_stripped) return new WP_Error('new_pass_no_match','New Password and Confirm Password must be the same');
if (!wp_check_password($currentPass_stripped, $oldPass)) return new WP_Error('current_pass_incorrect','Current Password is Incorrect');
// Change User's Password
wp_update_user( array(
'ID' => $uriData->author->ID,
'user_pass' => $newPass1_stripped
)
);
// Update the Password Cookie
$cookie_info = wp_get_cookie_login();
$login = $cookie_info['login'];
wp_clearcookie();
wp_setcookie($uriData->author->user_login, $newPass1);
$user = wp_get_current_user();
// Add a flag for Messaging the user that they have successfully changed their password
update_usermeta($user->ID, 'changed_password_my_account', 'yes');
// Redirect the User to My Account
return $message = 'You have successfully changed your password' ;
}