5

I would like to turn off the emails that the admin gets when a new user registers. We are getting a lot of emails because of new registrations (they are legitimate registrations) but I just don't want to see the email telling me that someone has signed up again and again.

So far I've tried installing plugins but they don't work. (support even says they don't work any longer). When searching around here the only question I was able to find was Turn off admin emails for new user registrations which is from three years ago and doesn't seem to work either. I tried with this code:

// 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 your blog %s:'), get_option('blogname')) . "rnrn";
    $message .= sprintf(__('Username: %s'), $user_login) . "rnrn";
    $message .= sprintf(__('E-mail: %s'), $user_email) . "rn";


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

        if ( empty($plaintext_pass) )
            return;

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

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

    }
}

to my theme functions.php (it has the line @wp_mail commented out) and I've even tried to comment out that line in wp-includes/pluggable.php but I still am getting the emails.

I'm using WordPress 4.5.3 right now. (UPDATED to 4.6 as part of this process)

I'm trying to be a clear as a can. I don't want the email that goes to the user to stop as they still should get that, but how can I make the email to admin stop?

18
  • 1
    Have you tried putting in the plugins folder? Commented Aug 16, 2016 at 18:47
  • i didn't know if it would help seeing as i edited the pluggable.php directly. Is this all i should have to comment out?
    – rudtek
    Commented Aug 16, 2016 at 18:54
  • 1
    Oops. Meant to post here. You don't want to edit any core files. That's why we use plugins. You can call pluggable from the plugin, but if it isn't needed, and it rarely is, you can just drop your code into a php file, upload to your plugin directory, activate. Commented Aug 16, 2016 at 18:56
  • 1
    They do not want us to be able to change that lol. You could just create filters at the server level in cPanel. Account-level filtering & User-level filtering. I'm convinced there is no resolve to this lol Commented Aug 17, 2016 at 0:24
  • 1
    Let us continue this discussion in chat. Commented Aug 17, 2016 at 19:17

5 Answers 5

5

Generic Pluggable Approach for WordPress < 4.6 (See @birgire's Answer for > 4.6)

Pluggable functions are one of the more depressing relics of WordPress's past and come with a slew of intricacies. That directly modifying the core file (which is entirely inadvisable, as @Jarmerson mentioned in the comments) did not work makes me suspect that another plugin in your installation may be overwriting the pluggable.

The wp-includes/pluggable.php file is loaded after active plugins and mu-plugins, but before the active theme; this means that the "Pluggable Functions" can only be superseded by declarations in a plugin.

The modification you discovered in the other answer applies to a much older version of WordPress. In the process of replacing any pluggable function, you should start with the original function as it exists in your installation's version (in your case, v4.5.3). In doing so, the solution becomes the following (comments omitted; no lines added, only removed):

function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) {
  if ( $deprecated !== null )
    _deprecated_argument( __FUNCTION__, '4.3.1' );

  if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) 
    return;

  global $wpdb, $wp_hasher;
  $user     = get_userdata( $user_id );
  $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  $key      = wp_generate_password( 20, false );

  do_action( 'retrieve_password_key', $user->user_login, $key );

  if ( empty( $wp_hasher ) ) {
    require_once ABSPATH . WPINC . '/class-phpass.php';
    $wp_hasher = new PasswordHash( 8, true );
  }

  $hashed = time() . ':' . $wp_hasher->HashPassword( $key );
  $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );

  $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
  $message .= __('To set your password, visit the following address:') . "\r\n\r\n";
  $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n";
  $message .= wp_login_url() . "\r\n";

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

I've omitted the traditional if( !function_exists() ) check that typically encapsulates a pluggable override because in this instance a potential duplicate declaration error is desirable - it would indicate that another plugin has overwritten the wp_new_user_notification() function before you, and thus that your attempt to do so is being completely ignored.

I'd recommend placing this function in a mu-plugin as it lessens the chance that another plugin should beat you to the punch. In any scenario, do not modify the core file wp-includes/pluggable.php with the above.

8
  • i tried this and get this error: Fatal error: Cannot redeclare wp_new_user_notification() (previously declared in /home/tdh/public_html/wp-includes/pluggable.php:1709) in /home/tdh/public_html/wp-content/themes/tdh/functions.php on line 71
    – rudtek
    Commented Aug 19, 2016 at 18:30
  • That error is due to the function wp_new_user_notification() already being declared. What you have to do is override it by including the function_exists() check it's wrapped in. If you include this, I believe your function will get priority over the WP core. Commented Aug 19, 2016 at 19:13
  • @Jarmerson the function_exists() check does overrides nothing - it completely skips your declaration of the function in the case that the function has already been declared. All it does is suppress a fatal collision error by ignoring your code.
    – bosco
    Commented Aug 19, 2016 at 19:29
  • @rudtek it looks like you dropped my solution into your theme. It must be placed in a plugin - pluggable function overrides in a theme will always fail.
    – bosco
    Commented Aug 19, 2016 at 19:29
  • 1
    He's on a stand alone. However I just tested your code on a fresh install and IT WORKS!!! :D @rudtek go into your plugins folder and simply create a new file e.g. disable-admin-notices.php and paste this just after the open tag /* Plugin Name: Disable Admin Email Notices */ then paste bosco's code and activate from plugins. Worked for me. Commented Aug 19, 2016 at 19:31
9

Approach for WordPress 4.6+

Check out the patch in ticket #36009 that was merged into WordPress version 4.6.

It adds the 'user' option for the $notify input parameter of wp_new_user_notification(), to skip sending those emails to the admin.

How it works

The register_new_user() function contains this part:

do_action( 'register_new_user', $user_id );

The email notifications are activated with:

add_action( 'register_new_user', 'wp_send_new_user_notifications' );

where the callback is defined as:

function wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
        wp_new_user_notification( $user_id, null, $notify );
}

Workaround

We could therefore try this approach (untested) with a custom callback and remove the default one:

add_action( 'init', function()
{
    remove_action( 'register_new_user',   'wp_send_new_user_notifications'         );
    add_action(    'register_new_user',   'wpse236122_send_new_user_notifications' );
} );

function wpse236122_send_new_user_notifications(  $user_id, $notify = 'user' )
{   
    wp_send_new_user_notifications( $user_id, $notify );    
}

where we change the default from 'both' to 'user'.

It's worth mentioning that wp_send_new_user_notifications() is also hooked into these actions:

  • network_site_new_created_user
  • network_site_users_created_user
  • network_user_new_created_user
  • edit_user_created_user

We could deal with them in a similar way as described above.

11
  • this seemed awesome. I updated to 4.6 and tried, but it still is sending me the new user notification.
    – rudtek
    Commented Aug 19, 2016 at 16:44
  • It's listed as a patch and requires unit testing. Untested waters. Commented Aug 19, 2016 at 18:18
  • I just tried this on a fresh install with zero plugins and default theme without luck. Commented Aug 19, 2016 at 19:21
  • I'm going to keep my eye on this, because this makes so much sense
    – rudtek
    Commented Aug 19, 2016 at 20:18
  • @Jarmerson Thanks for testing, I just noticed a small problem with my snippet, I will fix it ;-) Ps: the unit-test was added here.
    – birgire
    Commented Aug 19, 2016 at 20:26
3

For WordPress 6.1+

There are hooks you can use for handling the basic emails sent out:

add_filter('wp_send_new_user_notification_to_admin', '__return_false');
add_filter('wp_send_new_user_notification_to_user', '__return_false');

That will stop an install from sending emails with the subject pattern "[SITENAME] New User Registration".

2

After some research I determined that you can disable all notification emails, but not those that send to admin.

Per your original question, I can offer some advice on how to handle unwanted notification email from WordPress user registration and password reset email.

Assuming you have a cPanel environment running your installation, simply follow these steps and you will have effectively removed those particular email.

Access Account Level Filtering from the cPanel admin. In this area you can manage filters for your main account. You want to Create Filter and proceed to create a New Filter for All Mail on Your Account.

In the Rule field select To and equals. Note: You can also create filters for other conditions. The last field is a text area which you input the email address you're working with. Below the rules area is where the magic happens. Select Discard Message. There are also other options.

I've always created an email address I know wont be used and created the filter using it.

I could go on about WordPress pluggable hooks and such, but there is nothing that will do exactly as you would like. Bummer...

0
1

This worked for me. https://gist.github.com/someguy9/b24866f521ec3eb20b13feb4c72a6afd#file-disable-wordpress-admin-new-user-notification-php

    <?php
//Disable the new user notification sent to the site admin
function smartwp_disable_new_user_notifications() {
    //Remove original use created emails
    remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
    remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );
    
    //Add new function to take over email creation
    add_action( 'register_new_user', 'smartwp_send_new_user_notifications' );
    add_action( 'edit_user_created_user', 'smartwp_send_new_user_notifications', 10, 2 );
}
function smartwp_send_new_user_notifications( $user_id, $notify = 'user' ) {
    if ( empty($notify) || $notify == 'admin' ) {
      return;
    }elseif( $notify == 'both' ){
        //Only send the new user their email, not the admin
        $notify = 'user';
    }
    wp_send_new_user_notifications( $user_id, $notify );
}
add_action( 'init', 'smartwp_disable_new_user_notifications' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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