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?
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?
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"
My issue is resolved now. Thank you!