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

How to use password_change_email filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
October 31, 2022
5 minutes read

password_change_email filter

Filters the contents of the email sent when the user’s password is changed.

To use password_change_email filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.

We at WePlugins, always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.

In the below live example, we have defined a function modify_password_change_email_defaults which takes 3 parameters and we registered using add_filter. The first parameter password_change_email is name of the hook, The second parameter modify_password_change_email_defaults is name of the function which need to be called, third parameter is the priority of calling the hook if same hook is used multiple times and the last parameter is the number of arguments (if any) to be passed in the registered function.

Sometime, you have to remove a registered hook so you can use remove_filter to remove password_change_email filter.

Parameters

    Below are the 3 parameters required to use this hook.

  • $pass_change_email : (array) Used to build wp_mail().
    • to (string): The intended recipients. Add emails in a comma separated string.
    • subject (string): The subject of the email.
    • message (string): The content of the email. The following strings have a special meaning and will get replaced dynamically:
      • ###USERNAME###: The current user’s username.
      • ###ADMIN_EMAIL###: The admin email in case this was unexpected.
      • ###EMAIL###: The user’s email address.
      • ###SITENAME###: The name of the site.
      • ###SITEURL###: The URL to the site.
    • headers (string): Headers. Add headers in a newline (rn) separated string.
  • $user : (array) The original user array.
  • $userdata : (array) The updated user array.

Live Example 1

Below is an example of how you can use this hook.

    function weplugins_modify_password_change_email_defaults($pass_change_email, $user, $userdata) { 
        // Update the $pass_change_email variable according to your website requirements and return this variable. You can modify the $pass_change_email variable conditionally too if you want.
        return $pass_change_email; 
    }
    // add the filter
    add_filter( "password_change_email", "weplugins_modify_password_change_email_defaults", 10, 3 );
    

Live Example 2

To remove a hook callback, use the example below.

    remove_filter( "password_change_email", "weplugins_modify_password_change_email_defaults", 10, 3 );
    

Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Live Example 3

Change the admin email in notifications.

    function weplugins_change_admin_email($pass_change_email, $user, $userdata) {
        $pass_change_email['message'] = str_replace('###ADMIN_EMAIL###', 'admin@example.com', $pass_change_email['message']);
        return $pass_change_email;
    }
    add_filter('password_change_email', 'weplugins_change_admin_email', 10, 3);
    

Access Premium WordPress Plugins

If you need any customization, feel free to Contact Us.

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.