Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I turn off email notifications for the user and admin when a new user is registered?

I've seen a few suggestions and plugins but none appear to work. One was to take the function from one of the plugins:

if ( !function_exists('wp_new_user_notification') ) :
/**
 * Notify the blog admin of a new user, normally via email.
 *
 * @since 2.0
 *
 * @param int $user_id User ID
 * @param string $plaintext_pass Optional. The user's plaintext password
 */
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);

    // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    // we want to reverse this for the plain text arena of emails.
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

    $message  = sprintf(__('New user registration on your site %s:'), $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'), $blogname), $message);

    if ( empty($plaintext_pass) )
        return;

    $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
    $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
    $message .= wp_login_url() . "\r\n";

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

}
endif;

The questions and suggestions were quite old so maybe WP 3.5 over rides something.

On signup I'm still getting the admin email and an email to the user.

I don't want to block the forgotten password email though.

share|improve this question

1 Answer 1

Function wp_new_user_notification is pluggable. It means that you can override it by declaring your version of this function in your plugin/theme.

So, if you wish to disable all notifications completely, do it like this:

if ( !function_exists( 'wp_new_user_notification' ) ) :
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
    return;
}
endif;

However I wouldn't recommend you to disable all notifications, and would recommend you to send notification to an user at least (How does an user find out his password?). So in this case your code should be following:

if ( !function_exists( 'wp_new_user_notification' ) ) :
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
    $user = get_userdata( $user_id );

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

    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

    if ( empty($plaintext_pass) ) {
        return;
    }

    $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
    $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
    $message .= wp_login_url() . "\r\n";

    wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
}
endif;
share|improve this answer
1  
+1 @Rob ... how does a user get a password if you disable the notification? This is a very good point that Eugene Manuilov makes. –  s_ha_dum Mar 11 '13 at 14:08
    
@s_ha_dum I have some front end registration using gravity forms so that sends an email separately. Will this block the forgotten password email though? –  Rob Mar 11 '13 at 14:14
    
@EugeneManuilov I just tried the first code box but I'm still getting the emails. –  Rob Mar 11 '13 at 14:17
    
@Rob show us your code –  Eugene Manuilov Mar 11 '13 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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