apply_filters( ‘retrieve_password_notification_email’, array $defaults, string $key, string $user_login, WP_User $user_data )

Filters the contents of the reset password notification email sent to the user.

Parameters

$defaultsarray
The default notification email arguments. Used to build wp_mail() .
  • to string
    The intended recipient – user email address.
  • subject string
    The subject of the email.
  • message string
    The body of the email.
  • headers string
    The headers of the email.
$keystring
The activation key.
$user_loginstring
The username for the user.
$user_dataWP_User
WP_User object.

Source

$notification_email = apply_filters( 'retrieve_password_notification_email', $defaults, $key, $user_login, $user_data );

Changelog

VersionDescription
6.0.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Here’s an example of how you can use this inside functions.php:

    add_filter( 'retrieve_password_notification_email', 'wpdocs_reset_password_message', 99, 4 );
    function wpdocs_reset_password_message( $defaults, $key, $user_login, $user_data ) {
    	$password_reset_link = esc_url( network_site_url( "wp-login.php?action=rp&key={$key}&login=" . rawurlencode( $user_login ), 'login' ) );
    	$display_name = sprintf(
    		'%3$s (%2$s)',
    		esc_url( get_edit_profile_url( $user_data->ID ) ),
    		esc_html( $user_data->user_email ),
    		esc_html( $user_data->display_name )
    	);
    
    	$defaults['message'] = "The password for the following account has been requested to be reset:
    
    	{$display_name}
    
    	If this was a mistake, just ignore this email and nothing will happen.
    
    	To reset your password, visit the following address:
    
    	{$password_reset_link}";
    
    	return $defaults;
    }

    Inside the $defaults variable is an array with all the necessary data that you can modify.

    $defaults = array(
         'to'      => 'example@email.com',
         'subject' => 'Some subject...',
         'message' => 'Email message...',
         'headers' => '',
    );

You must log in before being able to contribute a note or feedback.