Skip Navigation

[Resolved] Customize Reset Password Email

This thread is resolved. Here is a description of the problem and solution.

Problem:

Customize email message of "Reset Password" email.

Solution:

The reset password email is setup by WordPress, you can try the WordPress built-in filter hook "retrieve_password_message"

Relevant Documentation:

https://developer.wordpress.org/reference/hooks/retrieve_password_message/

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by mikaelD 5 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1374289

I am trying to:

Use the retrieve_password_message hook to make the "Reset Password" email look a little bit nicer and more branded. I did this with the new registered user email.

Because my forgot password form is the using the Toolset shortcode form for password reset, I believe this hook may no longer work?

Does toolset provide a hook to modify the email body before it is sent?

#1374409

Hello,

The reset password email is setup by WordPress, you can try the WordPress built-in filter hook "retrieve_password_message":
https://developer.wordpress.org/reference/hooks/retrieve_password_message/

For example this thread:
https://wordpress.stackexchange.com/questions/321025/how-can-i-modify-the-default-reset-lost-password-email-text

#1374699

Hi,

Yes, I said in my request I already tried this, but the message does not update as expected. I tested a super simple version to ensure I coded it right, and still no luck. Here is the code:

add_filter( 'retrieve_password_message', 'custom_retrieve_password_message', 10, 4 );
function custom_retrieve_password_message( $retrieve_password_message, $key, $user_login, $user_data ) {
	
  
   $message = __( 'This is a test message.' );
  
    $retrieve_password_message['subject'] = __( 'Password Reset Request');
    $retrieve_password_message['headers'] = array('Content-Type: text/html; charset=UTF-8');
    $retrieve_password_message['message'] = $message;
 
    return $retrieve_password_message;
}

I placed this in a Toolset custom code snippet. It is active, and has no errors.

One weird thing occurs. I still get the default message that looks like this.

Someone has requested a password reset for the following account:

<em><u>hidden link</u></em>

Username: tester.

If this was a mistake, just ignore this email and nothing will happen.

To reset your password, visit the following address:

<em><u>hidden link</u></em>

With one caveat. The first letter is change to a "T" on the email body message. So it says "Tomeone" instead of "Someone".

If I changed this line of code:

$message = __( 'This is a test message.' );

to

$message = __( 'Hello' );

The word "Someone" in the default email changes to "Homeone". So it seems to be partially hooking into the message but breaking up somewhere. The subject line doesn't change at all. It stays as the default.

Any thoughts?

#1375265

Thanks for the details, two problem:
1) The filter hook "retrieve_password_message" works for mail message body of the password reset mail, it does not work for mail subject, see the document I mentioned above:
https://developer.wordpress.org/reference/hooks/retrieve_password_message/
See the example I mentioned above:
https://wordpress.stackexchange.com/questions/321025/how-can-i-modify-the-default-reset-lost-password-email-text

If you need to change the email subject, please try another filter hook: retrieve_password_title, see WordPress document
https://developer.wordpress.org/reference/hooks/retrieve_password_title/

2) The Toolset custom code snippet do not work for above WordPress filters, you can test them by putting into your theme file "functions.php"

#1375641

My issue is resolved now. Thank you!