Change the Text of Reset Password Email

Send a custom message to users who request a password re-set:

//* Password reset activation E-mail -> Body
add_filter( 'retrieve_password_message', 'dnlt_retrieve_password_message', 10, 2 );

function dnlt_retrieve_password_message( $message, $key ){
    $user_data = '';
    // If no value is posted, return false
    if( ! isset( $_POST['user_login'] )  ){
            return '';
    }
    // Fetch user information from user_login
    if ( strpos( $_POST['user_login'], '@' ) ) {

        $user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_user_by('login', $login);
    }
    if( ! $user_data  ){
        return '';
    }
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;
    // Setting up message for retrieve password
    $message = "A password reset has been requested for this site:\n\n";
    $message .= network_home_url( '/' ) . "\r\n\r\n";
    $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";  
    $message .= "Change this text to whatever you like.\n\n";
    $message .= "If you did not request this, just ignore this email and nothing will happen.\n\n"; 
    $message .= "To reset your password, visit the following address:\n";
    $message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');
    
    return $message;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar