Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use after_password_reset action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
December 30, 2022
5 minutes read

after_password_reset action

Alright, folks! Let’s dive into the after_password_reset action in WordPress. This hook fires right after a user’s password is reset. Now, to use this hook, you’ll need to register it with add_action. You can place the code in your theme’s functions.php file or, better yet, create a custom WordPress plugin so that your changes remain intact even when you update your theme. Here at WePlugins, we always prefer the plugin approach for this reason.

In the live example below, we define a function called weplugins_execute_on_after_password_reset_event which takes two parameters. We then register this function using add_action. The first parameter is the name of the hook (after_password_reset), the second parameter is the function name (weplugins_execute_on_after_password_reset_event), the third parameter is the priority, and the last parameter is the number of arguments to be passed to the function.

Sometimes, you might need to remove a registered hook, and you can do that using remove_action.

Parameters

    Below are the two parameters required to use this hook:

  • $user: (WP_User) The user.
  • $new_pass: (string) New user password.

Live Example 1

Here’s a basic example of how you can use this hook:

    function weplugins_execute_on_after_password_reset_event($user, $new_pass){
       // This code will be executed when the user's password is reset.
    }
    // Add the action
    add_action("after_password_reset", "weplugins_execute_on_after_password_reset_event", 10, 2);
    

Live Example 2

To remove a hook callback, use the example below:

    // Remove the action
    remove_action("after_password_reset", "weplugins_execute_on_after_password_reset_event", 10, 2);
    

Make sure you provide the same callback function name, priority, and number of arguments while removing the hook callback.

Live Example 3

Let’s say you want to send an email notification to the user after their password has been reset. Here’s how you can do it:

    function weplugins_send_password_reset_notification($user, $new_pass){
        $to = $user->user_email;
        $subject = "Your Password Has Been Reset";
        $message = "Hello " . $user->display_name . ",nnYour password has been successfully reset. If this wasn't you, please contact support immediately.";
        wp_mail($to, $subject, $message);
    }
    // Add the action
    add_action("after_password_reset", "weplugins_send_password_reset_notification", 10, 2);
    

Access Premium WordPress Plugins

Contact Us

If you need any customization or run into any issues using this hook, feel free to contact us. We’d be happy to assist you!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.