0

I want to disable the default email that is send when user is registered. I am using this plugin for email verification User Verification By PickPlugins, which sends an email with confirmation link, but the problem is that by default and WordPress send an email via pluggable.php:

function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ){...}

I am using a theme (which I am extending with a child theme), which calls wp_create_user. I have replaced that parent theme function and in my functions.php I have added:

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  );
}

The problem is, it still send both emails, from the plugin and default WordPress email for new user registration. I don't know how to disable this email.

3 Answers 3

0

Considering your code to be working, simply put it in a plugin. It should then work!

4
  • Why doesn't work in functions.php for the active theme, but will work in a plugin ?
    – gdfgdfg
    Feb 5, 2019 at 23:12
  • Long story short, it's related to the order of which plugins and theme load. Some hooks needs to fire before others. Feb 5, 2019 at 23:38
  • I have created a plugin and it is same. It seems that it doesn't hook the function.
    – gdfgdfg
    Feb 6, 2019 at 0:06
  • Even if I comment //add_action(register..., it still sends the default email.
    – gdfgdfg
    Feb 6, 2019 at 0:12
0

Move the parameter default into the function.

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 ){
    wp_new_user_notification( $user_id, null, 'user' );
}

Changed the wpse236122_send_new_user_notifications function to use the wp_new_user_notification as opposed to the action directly. Even though it works, it is more likely to break in a WordPress update.

I would also mention maybe instead of removing the action on init, use the register_new_user action and set at a lower priority. WordPress core uses 10 by default, so putting yours at 9 or below will work.

add_action( 'register_new_user', function(){
    remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
}, 9);
0

Tried several suggestions but they didn't work for me. Found a piece of code at SmartWP.com for disabling the admin notification and changed the code slightly and this one finally worked great

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_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 = 'admin' ) {
if ( empty($notify) || $notify == 'user' ) {
  return;
}elseif( $notify == 'both' ){
    //Only send the admin their email, not the user
    $notify = 'admin';
}
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.