admin管理员组

文章数量:1122832

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.

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.

Share Improve this question edited Feb 5, 2019 at 23:34 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Feb 5, 2019 at 23:03 gdfgdfggdfgdfg 1721 silver badge15 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 0

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

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

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

本文标签: Disable emails for new user registration