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.
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.
Below are the 3 parameters required to use this hook.
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 );
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.
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);
If you need any customization, feel free to Contact Us.
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.