0

Wordpress sends some various default email texts to the users.

For example when the password reset email has been sent, then the user gets an automatic email like this:

Hello user, This notification confirms the change of access password to NAMEOFWEBSITE. If you have not changed your password, please contact the Site Administrator at default-admin@email.com This message was sent to users-email@email.com Sincerely, All of us at NAMEOFWEBSITE https://www.nameofwebsite.com

I need to keep the default admin email that i set up in wordpress. But i need to filter all emails to have another email inside the text, like this :

Hello user, This notification confirms the change of access password to NAMEOFWEBSITE. If you have not changed your password, please contact the Site Administrator at another-email@email.com This message was sent to users-email@email.com Sincerely, All of us at NAMEOFWEBSITE https://www.nameofwebsite.com

Any ideas if this is possible with some filter?

1

There is definitely a filter for that!

Here is the reference link to wordpress developers page: https://developer.wordpress.org/reference/hooks/password_change_email/

Basically adding this function (with changes) to your functions.php will override your default password reset email.

apply_filters( 'password_change_email', array $pass_change_email, array $user, array $userdata )

full example:

add_filter( 'password_change_email', 'rt_change_password_mail_message', 10, 3 );

function rt_change_password_mail_message( $pass_change_mail, $user, $userdata ) {

 $new_message_txt = __( 'Hi [first_name] [last_name], 

 This notice confirms that your email was changed on on our site.

 If you did not change your email, please contact the Site Administrator on our site.

 This email has been sent to [user_email]

 Regards,
ME' );
 $pass_change_mail[ 'message' ] = $new_message_txt;
 return $pass_change_mail;

}

Checking the notes there, you'll see that the message is part of the $pass_change_email array. SO if you just want to add something to it try this...

add_filter( 'password_change_email', 'rt_change_password_mail_message', 10, 3 );

function rt_change_password_mail_message( $pass_change_mail, $user, $userdata ) {

 $new_message_txt = __( 'new text with phone number' );
 $pass_change_mail[ 'message' ] = $pass_change_mail[ 'message' ] . $new_message_txt;
 return $pass_change_mail;

}
| improve this answer | |
  • Thank you very much for your answer @rudtek . I understand your idea but as i don't really want to create a new email text for every different default wordpress email (another example developer.wordpress.org/reference/hooks/email_change_email ), i just want to filter the parameter value ###ADMIN_EMAIL### that is set in all emails and change it with another one. Any ideas on that :) ? – Honoluluman Aug 14 at 8:25
  • @Honoluluman You can simply change Administration Email in "Settings > General > Administration Email Address" – Ankit Aug 14 at 9:52
  • @Ankit thanks for the reply, but i need to keep the original admin email in "Settings > General > Administration Email Address" since i need to get all word press emails in that email. Just was looking for a hook to change the ###ADMIN_EMAIL### for users that receives some default emails and they can view the admin email. They should correspond in another email that i want to set up there. – Honoluluman Aug 14 at 10:08
  • @Honoluluman Please check my answer below, that may help you. – Ankit Aug 14 at 12:46
  • @Honoluluman try the 2nd option – rudtek Aug 14 at 14:58
0

I noticed that you want Administrator email to remain to some email, but you need to change the admin email in password and email change email.

So you can do following.

  1. Hook into email_change_email and password_change_email filters.
  2. You will get the parameter $email_change_email and $pass_change_email for those filters respectively inside callback function.
  3. Email text is present in $pass_change_email['message'], so you just have to look for the admin email in there and replace it with your new email address.
  4. Return the parameter from callback function.

This can be the example for password change email.

/**
 * Change admin email in password change email.
 */
function change_password_change_admin_email( array $pass_change_email ) {
    $admin_email = get_option('admin_email');
    $pass_change_email['message'] = str_replace( $admin_email, 'another-email@domain.com', $pass_change_email['message'] );

    return $pass_change_email;

}
add_filter( 'password_change_email', 'change_password_change_admin_email' );

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.