Disable WordPress notifications email for users and admins

Stop emailI’ve just had two separate issues in two days which needed me to try to disable WordPress notifications email. WordPress sends a lot of automated email, and it’s not so easy to see how to change or suppress it.

So I thought I’d share the solutions I found in case it saves anyone else time, or indeed if I forget how I managed it the next time I come across the problem.

1) Disable the automatic welcome email sent to users

WordPress always sends users an automated welcome email, which has their username and password, in plain text. This is bad – you really shouldn’t be receiving login details in plain text emails. The reason it does this is that on most WordPress sites, the user doesn’t get the chance to put in their own password, it’s generally created by WordPress and then – you guessed it – emailed to them.

I’ll put to one side that it really shouldn’t do this on this occasion and get to the point. On Smart Insights we allow our users to create their own password on sign-up using the s2member plugin that forms the backbone of our membership (more on that here). We also use a marketing automation platform called Office Auto Pilot (which is fantastic and highly recommended) which handles the bulk of our email.

Our users were getting confused by receiving two emails when they signed up – the (poor, text only) one from WordPress containing their username and password which they already knew, and then a minute later another (proper, formatted HTML) welcome from Office Auto Pilot.

So, I found out how to switch the WordPress notification off.

The function that handles new user notification is called, surprisingly, wp_new_user_notification. And upon inspection, this function is pluggable, which means you can override it entirely via a plugin. Note – a plugin – not your theme. This code will not work in your functions.php file – it must be run from a plugin. The codex shows the following code to override the email;


// Redefine user notification function
if ( !function_exists('wp_new_user_notification') ) {

function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {

$user = new WP_User( $user_id );

$user_login = stripslashes( $user->user_login );
 $user_email = stripslashes( $user->user_email );

$message = sprintf( __('New user registration on %s:'), get_option('blogname') ) . "\r\n\r\n";
 $message .= sprintf( __('Username: %s'), $user_login ) . "\r\n\r\n";
 $message .= sprintf( __('E-mail: %s'), $user_email ) . "\r\n";

@wp_mail(
 get_option('admin_email'),
 sprintf(__('[%s] New User Registration'), get_option('blogname') ),
 $message
 );

if ( empty( $plaintext_pass ) )
 return;

$message = __('Hi there,') . "\r\n\r\n";
 $message .= sprintf( __("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "\r\n\r\n";
 $message .= wp_login_url() . "\r\n";
 $message .= sprintf( __('Username: %s'), $user_login ) . "\r\n";
 $message .= sprintf( __('Password: %s'), $plaintext_pass ) . "\r\n\r\n";
 $message .= sprintf( __('If you have any problems, please contact me at %s.'), get_option('admin_email') ) . "\r\n\r\n";
 $message .= __('Adios!');

wp_mail(
 $user_email,
 sprintf( __('[%s] Your username and password'), get_option('blogname') ),
 $message
 );
 }
}

Using that would allow you to tweak the welcome message to something a bit more detailed and ‘on-brand’ than the default one, which is useful info in itself. In my case though, all I wanted to do is stop it from sending the email at all. So, this did it for me;


if ( !function_exists('wp_new_user_notification') ) {

function wp_new_user_notification( ) {}

}

2) Disable the ‘user x has changed their password’ emails to the admin account

We use Help Scout for handling all of our user support, it’s simple and cheap (unlike Zendesk which from experience is neither of those) and does the job perfectly.  All emails sent by WordPress to the admin account are forwarded to Help Scout which handles them and assigns them out to support representatives. We use some of the notifications – comments and pingbacks, but we get lots of the ‘user x has changed their password’ emails, and we have to delete each support case generated by Help Scout manually. It’s annoying.

Another pluggable function to the rescue – wp_password_change_notification, which we can suppress be adding the following to a plugin – you can add this to the same plugin file you created for 1) if you like – it’ll work fine;

if ( !function_exists( 'wp_password_change_notification' ) ) {
    function wp_password_change_notification() {}
}

What about other automated emails?

Chances are there’s a pluggable function that allows you to suppress it – here’s a few more;

  • wp_notify_moderator – notifies the moderator of the blog about a new comment that is awaiting approval.
  • wp_notify_postauthor – responsible for sending comment notification emails to the post author when a reader leaves a comment

Take a look at the full list of pluggable functions at the Codex.