12

So, WordPress 4.3 has a new password system as we all know. Unfortunately, this new system has done away with the ability to NOT send new users an email.

My client was using a system where he sent a custom email to his clients, manually registering their emails, and then sending them an email with the login info with a custom message. We are aware that this new system is trying to be more secure, but this isn't working for the amount of control he would like.

I've found the following code in my search for a solution to turn these emails off, but I think they only turn off the notification emails for if a user's email is CHANGED for previously registered users, not when it's first created:

add_filter( 'send_password_change_email', '__return_false');
add_filter( 'send_email_change_email', '__return_false');

Does anyone know of any way to turn off these initial password emails sent after registration?

Thank you.

  • 2
    Have you tried this? add_filter( 'user_registration_email', '__return_false'); – Abhik Aug 23 '15 at 5:06
8

You can intercept this email before it is sent using the phpmailer_init hook.

By default, this hook fires before any email is sent. In the function below, $phpmailer will be an instance of PHPMailer, and you can use its methods to remove the default recipient and manipulate the email before it is sent.

add_action('phpmailer_init', 'wse199274_intercept_registration_email');
function wse199274_intercept_registration_email($phpmailer){
    $admin_email = get_option( 'admin_email' );

    # Intercept username and password email by checking subject line
    if( strpos($phpmailer->Subject, 'Your username and password info') ){
        # clear the recipient list
        $phpmailer->ClearAllRecipients();
        # optionally, send the email to the WordPress admin email
        $phpmailer->AddAddress($admin_email);
    }else{
        #not intercepted
    }
}
  • this works flawlessly, completely solved my issue and is perfect for other uses as well. Thanks for a great answer! – pattyd Feb 19 '17 at 20:33
3

Actually it depends how you create the new user. If you do it from administration - Users - Add New you are right. In 4.3 unfortunatelly you cannot disable sending the notification email. But if you really want to create a new user without the email, there is a way.

You can create a small plugin where you'd create a new account by yourself via wp_insert_user function, which doesn't send any email by default.

This function can be called like this.

wp_insert_user( $userdata );

Where the userdata parameter is an array where you can pass all needed information.

$userdata = array(
    'user_login'  =>  'login',
    'user_pass'   =>  'password',
);

$user_id = wp_insert_user( $userdata ) ;

//On success
if ( ! is_wp_error( $user_id ) ) {
    echo "User created : ". $user_id;
}

For more informations check codex here.

  • So this function is called whenever a new user is created I'm assuming? – Lisa Cerilli Aug 23 '15 at 4:55
3

The wp_new_user_notification function is pluggable, so you can override it by defining your own. You should be able to copy the entire function from wp-includes/pluggable.php into your plugin (or functions.php) and remove the line that sends out the email.

  • 1
    You can't override wp_new_user_notification in theme's functions.php, because pluggable functions are loaded before theme. It must be overriden in plugin or mu-plugin. Read more: wordpress.stackexchange.com/a/55966/56759 – fandasson Oct 16 '15 at 13:16
1

To solve this in your theme create new mu-plugin by creating new file wp_new_user_notifications.php (name is up to you) and put it in wp-content/mu-plugins folder. If there is no folder like that, create one. Remember to put the php file directly into the folder, not to any subfolder.

Than continue as Simon suggested - copy wp_new_user_notifications.php method from wp-includes/pluggable.php into your brand new wp_new_user_notifications.php file and modify as needed.

To answer your question: for turning off initial password e-mails is enough to remove last wp_mail method call.

0
add_filter('send_password_change_email', '__return_false');

Works. But its essential that its added to the plugin it self and not the functions.php for the theme.

Like.

class ... {
  public function __construct() {
    ...
    $this->init_hooks();
  }

  public function init_hooks() {
    add_filter('send_password_change_email', '__return_false');
  }
}

protected by fuxia May 5 '16 at 13:10

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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