I’m using the Theme My Login WordPress plugin. My aim is to filter ‘retrieve_password_message’ – Just to make some minor text changes to the email that gets sent out when a user requests a password reset.
My code:
function filter_reset_password_request_email_body( $message, $key, $user_id ) {
$user_login = bp_core_get_username( $user_id );
$message .= sprintf( __( 'Password reset request for %s' ), $user_login ) . "rnrn";
$message .= __( 'If this was not you, please ignore this email and nothing will happen.' ) . "rnrn";
$message .= __( 'To reset your password, visit the following link:' ) . "rnrn";
$message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "rn";
return $message;
}
add_filter( 'retrieve_password_message', 'filter_reset_password_request_email_body', 10, 3 );
The problem is – when using this filter, the email that gets sent out displays the filtered message directly underneath the original (unfiltered) message. I just need the filtered message to display in the email body.
Am I doing anything wrong or could this be a bug with Theme My Login?
Hoping somebody can throw some light on this.
Notes: I’m using BuddyPress which is why I can use bp_core_get_username
to get the user’s username.
In the 5th line of your code, where you first reference
$message
, remove the.
before the=
symbol. I.e.What’s happening with your current implementation is that it’s appending your custom message to the end of what was passed through the filter. You instead just want to “reset”
$message
to begin with your message.