_k

Disable new user admin emails in Wordpress

This tip will only work in Wordpress 4.6.0 and higher, as the funtion I’m using is less configurable in earlier versions

I recently had the need to disable the admin notification email Wordpress sends when a new user was registered programmatically.

Instead of using a plugin you can use the function wp_new_user_notification to control who gets an email at registration time.

The function takes three parameters.

<?php
wp_new_user_notification(int $user_id,
[null $deprecated = null, string $notify = '']);
?>

The third parameter is the one we need, it takes three diffrent values.

  • admin (or empty string)
  • user
  • both

Which are pretty self-explanatory admin sends an email to the admin, user to the user and both to the admin and the user.

You can read more about this function at the Wordpress documentation.

As the documentation states the function is meant to be overridden by plugins or themes, which makes it the perfect place to customize your registration mail content too.

To hook into the default registration notification you just need to unhook the default Wordpress call to the function in your theme or plugin and set it up as you need it.

<?php
remove_action('register_new_user', 'wp_send_new_user_notifications');

function my_custom_user_notifications( $user_id, $notify = 'user' ) {
  wp_new_user_notification( $user_id, null, $notify );
}
add_action('register_new_user', 'my_custom_user_notifications', 10);
?>