Skip to content

Instantly share code, notes, and snippets.

@Rodgath
Last active July 9, 2025 08:53
Show Gist options
  • Save Rodgath/ebc3bcbe0dc2a661fae00e0f5787c486 to your computer and use it in GitHub Desktop.
Save Rodgath/ebc3bcbe0dc2a661fae00e0f5787c486 to your computer and use it in GitHub Desktop.
Restore WordPress User Password Using Email
/**
* Reset a user's password by email.
*
* @param string $password New plain-text password.
* @param string $user_email User's email address.
*/
function custom_reset_password($password, $user_email) {
$user = get_user_by('email', $user_email);
if ($user && !is_wp_error($user)) {
wp_set_password($password, $user->ID);
// Optional: log user out of all sessions
wp_clear_auth_cookie();
}
}
// Example usage
custom_reset_password('MY_NEW_PASSWORD', '[email protected]');
/**
* INSTRUCTIONS:
* =============
* - Paste this code in your theme's functions.php file
* - Visit your homepage OR any other page
* - Delete this custom code from functions.php after password reset
* - Login with your new password
* - Done!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment