Using WordPress ‘password_change_email’ PHP filter

The password_change_email WordPress PHP filter allows you to modify the contents of the email sent when a user’s password is changed.

Usage

add_filter('password_change_email', 'your_custom_function', 10, 3);

function your_custom_function($pass_change_email, $user, $userdata) {
  // your custom code here
  return $pass_change_email;
}

Parameters

  • $pass_change_email (array): An array containing information used to build the wp_mail() function.
  • $user (array): The original user array.
  • $userdata (array): The updated user array.

More information

See WordPress Developer Resources: password_change_email

Examples

Change the email subject

To customize the email subject when a user’s password is changed:

add_filter('password_change_email', 'change_password_email_subject', 10, 3);

function change_password_email_subject($pass_change_email, $user, $userdata) {
  $pass_change_email['subject'] = 'Your password has been updated!';
  return $pass_change_email;
}

Add a custom message to the email body

To add a custom message to the email body:

add_filter('password_change_email', 'add_custom_message', 10, 3);

function add_custom_message($pass_change_email, $user, $userdata) {
  $custom_message = 'Thank you for keeping your account secure!';
  $pass_change_email['message'] .= "\n\n" . $custom_message;
  return $pass_change_email;
}

Change the email recipient

To change the recipient of the password change email:

add_filter('password_change_email', 'change_email_recipient', 10, 3);

function change_email_recipient($pass_change_email, $user, $userdata) {
  $pass_change_email['to'] = '[email protected]';
  return $pass_change_email;
}

Add custom email headers

To add custom email headers:

add_filter('password_change_email', 'add_custom_email_headers', 10, 3);

function add_custom_email_headers($pass_change_email, $user, $userdata) {
  $pass_change_email['headers'] = "From: Custom Sender <[email protected]>\r\n";
  return $pass_change_email;
}