From daa3fe4d266d9563d285df3d6b2ee09fffdba23a Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 25 Nov 2015 22:37:35 +0000 Subject: [PATCH] Users: Allow to create users without sending an email to the new user. This adds a checkbox to `wp-admin/user-new.php` to prevent sending an email with the username and a password reset link to the new user. Restores the behavior of pre-4.3. Fixes #33504. Props tharsheblows, SergeyBiryukov, DrewAPicture, ocean90. git-svn-id: https://develop.svn.wordpress.org/trunk@35742 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/user.php | 8 ++++++-- src/wp-admin/user-new.php | 7 +++++-- src/wp-includes/default-filters.php | 2 +- src/wp-includes/user.php | 8 +++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php index e855e2e17d..3d37bdf579 100644 --- a/src/wp-admin/includes/user.php +++ b/src/wp-admin/includes/user.php @@ -176,14 +176,18 @@ function edit_user( $user_id = 0 ) { $user_id = wp_update_user( $user ); } else { $user_id = wp_insert_user( $user ); + $notify = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin'; + /** * Fires after a new user has been created. * * @since 4.4.0 * - * @param int $user_id ID of the newly created user. + * @param int $user_id ID of the newly created user. + * @param string $notify Type of notification that should happen. See {@see wp_send_new_user_notifications()} + * for more information on possible values. */ - do_action( 'edit_user_created_user', $user_id ); + do_action( 'edit_user_created_user', $user_id, $notify ); } return $user_id; } diff --git a/src/wp-admin/user-new.php b/src/wp-admin/user-new.php index 0f16b28b2a..ff0bffb840 100644 --- a/src/wp-admin/user-new.php +++ b/src/wp-admin/user-new.php @@ -368,7 +368,7 @@ $new_user_lastname = $creating && isset( $_POST['last_name'] ) ? wp_unslash( $_P $new_user_email = $creating && isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : ''; $new_user_uri = $creating && isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : ''; $new_user_role = $creating && isset( $_POST['role'] ) ? wp_unslash( $_POST['role'] ) : ''; -$new_user_send_password = $creating && isset( $_POST['send_password'] ) ? wp_unslash( $_POST['send_password'] ) : true; +$new_user_send_notification = $creating && ! isset( $_POST['send_user_notification'] ) ? false : true; $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unslash( $_POST['noconfirmation'] ) : ''; ?> @@ -418,7 +418,6 @@ $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unsl -

@@ -436,6 +435,10 @@ $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unsl + + + + diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 0cd9e5c6a6..1faa084cf7 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -357,7 +357,7 @@ add_action( 'comment_post', 'wp_new_comment_notify_moderator' ); add_action( 'comment_post', 'wp_new_comment_notify_postauthor' ); add_action( 'after_password_reset', 'wp_password_change_notification' ); add_action( 'register_new_user', 'wp_send_new_user_notifications' ); -add_action( 'edit_user_created_user', 'wp_send_new_user_notifications' ); +add_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 ); // REST API actions. add_action( 'init', 'rest_api_init' ); diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 65ea0eef65..32b0ec7463 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -2198,10 +2198,12 @@ function register_new_user( $user_login, $user_email ) { * * @since 4.4.0 * - * @param int $user_id ID of the newly created user. + * @param int $user_id ID of the newly created user. + * @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty string + * (admin only), or 'both' (admin and user). Default 'both'. */ -function wp_send_new_user_notifications( $user_id ) { - wp_new_user_notification( $user_id, null, 'both' ); +function wp_send_new_user_notifications( $user_id, $notify = 'both' ) { + wp_new_user_notification( $user_id, null, $notify ); } /**