Support » Plugin: Disable New User Notification Emails » There’s an easier way to do this

  • I don’t think it’s necessary to replace the whole pluggable function to achieve the goal of stopping the “new user” notification email being sent to admin. This plugin changes more than just the part of the wp_new_user_notification function that sends email to admin.

    I found that WordPress wraps the wp_new_user_notification function with function wp_send_new_user_notifications, which is in turn added using add_action to ‘register_new_user’ and ‘edit_user_created_user’.

    The function wp_send_new_user_notifications has only one line of code which is to call wp_new_user_notification.

    So I think you can do this instead:

    remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
    remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10 );
    add_action( 'register_new_user', array('yourclassname', 'wp_send_new_user_notifications'), 10, 2 );
    add_action( 'edit_user_created_user', array('yourclassname', 'wp_send_new_user_notifications'), 10, 2 );
    
    public static function wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
    	wp_new_user_notification( $user_id, null, 'user' );
    }

    In other words, remove the default actions and add back your own, with the $notify parameter hardcoded to “user” so only the user gets the email, not admin.

    I’m doing it a plugin but that shouldn’t be necessary because you no longer need to replace a pluggable function.

Viewing 11 replies - 1 through 11 (of 11 total)
  • @salubritas – I’m trying to disable the admin email notification without using a plugin. I’m just wondering in the above code you mentioned, what should I replace “yourclassname” in my code? looking forward to hearing from you. Thanks!

    Thread Starter salubritas

    (@salubritas)

    If you are doing it via functions.php it should work with something like:

    remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
    remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10 );
    add_action( 'register_new_user', 'mytheme_wp_send_new_user_notifications', 10, 2 );
    add_action( 'edit_user_created_user', 'mytheme_wp_send_new_user_notifications', 10, 2 );
    
    public static function mytheme_wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
    	wp_new_user_notification( $user_id, null, 'user' );
    }

    Untested!

    Hey @salubritas – There seems to be a syntax error from your code.
    See screenshot: https://prnt.sc/r2moza

    I wanted to try out your code by inserting it into my function.php Child theme, hoping it’ll work. I’ve tried tons of different plugins and snippets but none seem to work anymore. THE GOAL IS TO DISABLE WordPress from sending notification email to the Admin whenever there’s a New User Registration. That’s all I need.

    Let me me know if you can much. Much appreciate it. Thanks.

    KV

    Thread Starter salubritas

    (@salubritas)

    Remove “public static” from the function declaration. That’s for when it is inside a class.

    @salubritas – Thanks mate! That did disable Email sent to the Admin, but now WP sends the notification to the user even though I unchecked this box: https://prnt.sc/r2ubes

    I’m using a Child Theme.

    I found a script to create a custom plugin, that seems to work, but it disables both Admin and to User notifications at the same time. I didn’t want to risk New Account Notices not being sent to the customer after they Register for an Account during Checkout, using Woocommerce, ec.

    // Disable WordPress Admin Notfication From New User Registration
    if ( !function_exists( ‘wp_new_user_notification’ ) ) :
    function wp_new_user_notification( $user_id, $plaintext_pass = ” ) {
    return;
    }
    endif;

    I just need for the Notification to Admin to be disabled when a New User Registration is made.

    Thread Starter salubritas

    (@salubritas)

    I think we discovered that as well and changed it a little.

    function mytheme_wp_send_new_user_notifications( $user_id, $notify = 'user' ) {
    		switch($notify) {
    			case 'admin':
    				$notify = 'none';
    				break;
    			case 'both':
    				$notify = 'user';
    				break;
    		}
    		wp_new_user_notification($user_id, null, $notify);
    	}

    @salubritas – That revised script didn’t quite worked. It disable notification to the User but still sends one to the Admin, after I manually added a new user as a customer or subscriber to test.

    The script for the plugin I showed you prior, that did work to stop both notifications, you think it’s a good idea to use it? I’m a bit weary of using a plugin for this purpose though. I just need the notification to Admin on new user registration to stop, that is all. Not finding a solution on Google search.

    Thread Starter salubritas

    (@salubritas)

    We use the remove action/add action above with the function provided. It needs the remove/add actions or it won’t do anything.

    It does exactly what we want which is not send a notification to admin but sends a notification to the user if the box is ticked.

    If you are not a developer it’s best to get one to integrate the code for you. I don’t recommend simply copying and pasting code you find without first understanding what it is doing.

    Yeah I hear you, your revised code looks proper, but I guess WP Admin is a bit tricky to manipulate.

    I’ll install that plugin for now and do some live order testing with customer new account and change password option, etc and see if those notification still comes through.

    Thanks mate!

    Oh wait, I misread your comment. So you’re saying to combine the add action code with the function you had provided. Now it works! This is what I used:

    remove_action( ‘register_new_user’, ‘wp_send_new_user_notifications’ );
    remove_action( ‘edit_user_created_user’, ‘wp_send_new_user_notifications’, 10 );
    add_action( ‘register_new_user’, ‘mytheme_wp_send_new_user_notifications’, 10, 2 );
    add_action( ‘edit_user_created_user’, ‘mytheme_wp_send_new_user_notifications’, 10, 2 );

    function mytheme_wp_send_new_user_notifications( $user_id, $notify = ‘user’ ) {
    switch($notify) {
    case ‘admin’:
    $notify = ‘none’;
    break;
    case ‘both’:
    $notify = ‘user’;
    break;
    }
    wp_new_user_notification($user_id, null, $notify);
    }

    @salubritas – Hey buddy Thanks for helping me out earlier with the previous function codes, works great.

    However, I noticed when the customer clicks on the Forget Password link to reset and change their password, WordPress sends the notification to Admin as well.

    Can you show me the additional lines of codes to add to disable this? Thanks.

    KV

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘There’s an easier way to do this’ is closed to new replies.