The after_password_reset WordPress PHP action fires after a user’s password has been reset.
Usage
add_action('after_password_reset', 'your_custom_function', 10, 2);
function your_custom_function($user, $new_pass) {
// your custom code here
}
Parameters
$user(WP_User): The user whose password has been reset.$new_pass(string): The new password for the user.
More information
See WordPress Developer Resources: after_password_reset
Examples
Send a password reset confirmation email
Send an email to the user confirming that their password has been successfully reset.
function send_password_reset_email($user, $new_pass) {
$to = $user->user_email;
$subject = 'Your password has been reset';
$message = 'Your password has been successfully reset. Please use your new password to log in.';
wp_mail($to, $subject, $message);
}
add_action('after_password_reset', 'send_password_reset_email', 10, 2);
Log password reset event
Log the password reset event for security and audit purposes.
function log_password_reset($user, $new_pass) {
$log_message = "Password reset for user {$user->user_login} (ID: {$user->ID})";
error_log($log_message);
}
add_action('after_password_reset', 'log_password_reset', 10, 2);
Notify admin of password reset
Send an email notification to the site administrator when a user’s password has been reset.
function notify_admin_password_reset($user, $new_pass) {
$admin_email = get_option('admin_email');
$subject = "User {$user->user_login} has reset their password";
$message = "User {$user->user_login} (ID: {$user->ID}) has reset their password.";
wp_mail($admin_email, $subject, $message);
}
add_action('after_password_reset', 'notify_admin_password_reset', 10, 2);
Force password change on next login
Mark the user’s password as temporary, forcing them to change it on their next login.
function force_password_change_on_next_login($user, $new_pass) {
update_user_meta($user->ID, '_force_password_change', true);
}
add_action('after_password_reset', 'force_password_change_on_next_login', 10, 2);
Add a custom event to the user activity log
Add a custom event to the user activity log plugin when a user’s password has been reset.
function log_user_activity_password_reset($user, $new_pass) {
$activity_data = array(
'user_id' => $user->ID,
'activity' => 'Password reset',
'description' => "User {$user->user_login} (ID: {$user->ID}) has reset their password.",
'date' => current_time('mysql')
);
insert_user_activity_log($activity_data);
}
add_action('after_password_reset', 'log_user_activity_password_reset', 10, 2);