From 5dc1150ea2bbb3194805c14dcde055fc64be212b Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 12 Jul 2022 21:05:16 +0000 Subject: [PATCH] Users: Allow conditional supression of the email notifications that are sent when a new user account is registered. This introduces the following new filters: * `wp_send_new_user_notification_to_admin` * `wp_send_new_user_notification_to_user` Props janthiel, costdev, audrasjb, peterwilsoncc Fixes #54874 Built from https://develop.svn.wordpress.org/trunk@53698 git-svn-id: http://core.svn.wordpress.org/trunk@53257 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/pluggable.php | 24 ++++++++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index bd80946c0c..2931fd892c 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -2110,7 +2110,17 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) : // We want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); - if ( 'user' !== $notify ) { + /** + * Filters whether the admin is notified of a new user registration. + * + * @since 6.1.0 + * + * @param bool $send Whether to send the email. Default true. + * @param WP_User $user User object for new user. + */ + $send_notification_to_admin = apply_filters( 'wp_send_new_user_notification_to_admin', true, $user ); + + if ( 'user' !== $notify && true === $send_notification_to_admin ) { $switched_locale = switch_to_locale( get_locale() ); /* translators: %s: Site title. */ @@ -2158,8 +2168,18 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) : } } + /** + * Filters whether the user is notified of their new user registration. + * + * @since 6.1.0 + * + * @param bool $send Whether to send the email. Default true. + * @param WP_User $user User object for new user. + */ + $send_notification_to_user = apply_filters( 'wp_send_new_user_notification_to_user', true, $user ); + // `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification. - if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) { + if ( 'admin' === $notify || true !== $send_notification_to_user || ( empty( $deprecated ) && empty( $notify ) ) ) { return; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 3fad10eef5..a5ba84fba1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53692'; +$wp_version = '6.1-alpha-53698'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.