Membership 2 Customize the Reset Password Email

Is there a way to customize the reset password email? I looked in the Membership 2 => Setting => Automated Email Responses => Templates but did not see this one as an option.

Any thoughts on how to go about this?

Thanks,
William

  • Ash

    Hello @William

    I hope you are well today and thanks for asking the question.

    You can try the following code:

    add_filter( 'retrieve_password_message', 'retrieve_password_message_cb', 99, 3 );
    function retrieve_password_message_cb( $message, $key, $url ) {
        // Write your new message
        $message = '.....';
        return $message;
    
    }

    You can configure with your own message in the $message variable.

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • William

    Hi @Ashok,

    Thanks for your reply. I was however able to find a bit of a more custom solution online. This solution allows me to change and customize everything rather than just the message. I wraped it up into a plugin as well.

    Plugin:

    <?php
    /*
    Plugin Name: Better WP Email & Custom Lost Password
    Description: Change the default address and name/site-name that WordPress sends it's email from and customize the Forgot Password email.
    Version: 1.0
    */
    //* Change "From" email address
    add_filter( 'wp_mail_from', function( $email ) {
    	return 'email@website.com';
    });
    //* Change "From" email name
    add_filter( 'wp_mail_from_name', function( $name ) {
    	return 'Your Name or Site Name';
    });
    //* Change Subject
    add_filter( 'retrieve_password_title', function() {
    	return 'Password Recovery';
    });
    //* Change email type to HTML
    add_filter( 'wp_mail_content_type', function( $content_type ) {
    	return 'text/html';
    });
    //* Change the message/body of the email
    add_filter( 'retrieve_password_message', 'rv_new_retrieve_password_message', 10, 2 );
    function rv_new_retrieve_password_message( $message, $key ){
    	// Bail if username or email is not entered
    	if ( ! isset( $_POST['user_login'] ) )
    		return;
    	// Get user's data
    	if ( strpos( $_POST['user_login'], '@' ) ) { # by email
    		$user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
    	} else { # by username
    		$login = trim( $_POST['user_login'] );
    		$user_data = get_user_by( 'login', $login );
    	}
    	// Store some info about the user
    	$user_fname = $user_data->user_firstname;
    	$user_login = $user_data->user_login;
    	$user_email = $user_data->user_email;
    	// Assembled the URL for resetting the password
    	$reset_url = add_query_arg(array(
    		'action' => 'rp',
    		'key' => $key,
    		'login' => rawurlencode( $user_login )
    	), wp_login_url() );
    	// Create and return the message
    	$message = sprintf( '<p>%s</p>', __( 'Hi ' ) . $user_fname );
    	$message .= sprintf( '<p>%s</p>', __( 'It looks like you need to reset your password on the site. If this is correct, simply click the link below. If you were not the one responsible for this request, ignore this email and nothing will happen.' ) );
    	$message .= sprintf( '<p><a href="%s">%s</a></p>', $reset_url, __( 'Reset Your Password' ) );
    	return $message;
    }
    ?>

    Thanks,
    William

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.