The reset_password() WordPress PHP function handles resetting a user’s password.
Usage
reset_password($user, $new_pass);
Example:
Input:
$user_id = 1; $new_pass = 'new_password123'; $user = get_user_by('id', $user_id); reset_password($user, $new_pass);
Output:
The password for user with ID 1 is changed to ‘new_password123’.
Parameters
$user (WP_User)
– Required. The user whose password needs to be reset.$new_pass (string)
– Required. New password for the user in plaintext.
More information
See WordPress Developer Resources: reset_password()
Examples
Reset Password by User ID
Resets the password for a user with a specified user ID.
$user_id = 1; $new_pass = 'new_password123'; $user = get_user_by('id', $user_id); reset_password($user, $new_pass);
Reset Password by User Email
Resets the password for a user with a specified email address.
$email = '[email protected]'; $new_pass = 'new_password123'; $user = get_user_by('email', $email); reset_password($user, $new_pass);
Reset Password by User Login
Resets the password for a user with a specified username (user_login).
$username = 'john_doe'; $new_pass = 'new_password123'; $user = get_user_by('login', $username); reset_password($user, $new_pass);
Reset Password for Current User
Resets the password for the currently logged-in user.
$current_user = wp_get_current_user(); $new_pass = 'new_password123'; reset_password($current_user, $new_pass);
Reset Password and Send Notification
Resets the password for a user with a specified user ID and sends a notification email.
$user_id = 1; $new_pass = 'new_password123'; $user = get_user_by('id', $user_id); reset_password($user, $new_pass); wp_new_user_notification($user_id, $new_pass);