There’s an easier way to do this
-
I don’t think it’s necessary to replace the whole pluggable function to achieve the goal of stopping the “new user” notification email being sent to admin. This plugin changes more than just the part of the wp_new_user_notification function that sends email to admin.
I found that WordPress wraps the wp_new_user_notification function with function wp_send_new_user_notifications, which is in turn added using add_action to ‘register_new_user’ and ‘edit_user_created_user’.
The function wp_send_new_user_notifications has only one line of code which is to call wp_new_user_notification.
So I think you can do this instead:
remove_action( 'register_new_user', 'wp_send_new_user_notifications' ); remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10 ); add_action( 'register_new_user', array('yourclassname', 'wp_send_new_user_notifications'), 10, 2 ); add_action( 'edit_user_created_user', array('yourclassname', 'wp_send_new_user_notifications'), 10, 2 ); public static function wp_send_new_user_notifications( $user_id, $notify = 'both' ) { wp_new_user_notification( $user_id, null, 'user' ); }
In other words, remove the default actions and add back your own, with the $notify parameter hardcoded to “user” so only the user gets the email, not admin.
I’m doing it a plugin but that shouldn’t be necessary because you no longer need to replace a pluggable function.
- The topic ‘There’s an easier way to do this’ is closed to new replies.