turn off new user registration emails

Generic Pluggable Approach for WordPress < 4.6 (See @birgire’s Answer for > 4.6)

Pluggable functions are one of the more depressing relics of WordPress’s past and come with a slew of intricacies. That directly modifying the core file (which is entirely inadvisable, as @Jarmerson mentioned in the comments) did not work makes me suspect that another plugin in your installation may be overwriting the pluggable.

The wp-includes/pluggable.php file is loaded after active plugins and mu-plugins, but before the active theme; this means that the “Pluggable Functions” can only be superseded by declarations in a plugin.

The modification you discovered in the other answer applies to a much older version of WordPress. In the process of replacing any pluggable function, you should start with the original function as it exists in your installation’s version (in your case, v4.5.3). In doing so, the solution becomes the following (comments omitted; no lines added, only removed):

function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) {
  if ( $deprecated !== null )
    _deprecated_argument( __FUNCTION__, '4.3.1' );

  if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) 
    return;

  global $wpdb, $wp_hasher;
  $user     = get_userdata( $user_id );
  $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  $key      = wp_generate_password( 20, false );

  do_action( 'retrieve_password_key', $user->user_login, $key );

  if ( empty( $wp_hasher ) ) {
    require_once ABSPATH . WPINC . '/class-phpass.php';
    $wp_hasher = new PasswordHash( 8, true );
  }

  $hashed = time() . ':' . $wp_hasher->HashPassword( $key );
  $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );

  $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
  $message .= __('To set your password, visit the following address:') . "\r\n\r\n";
  $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n";
  $message .= wp_login_url() . "\r\n";

  wp_mail($user->user_email, sprintf(__('[%s] Your username and password info'), $blogname), $message);
}

I’ve omitted the traditional if( !function_exists() ) check that typically encapsulates a pluggable override because in this instance a potential duplicate declaration error is desirable – it would indicate that another plugin has overwritten the wp_new_user_notification() function before you, and thus that your attempt to do so is being completely ignored.

I’d recommend placing this function in a mu-plugin as it lessens the chance that another plugin should beat you to the punch. In any scenario, do not modify the core file wp-includes/pluggable.php with the above.

Leave a Comment