From 9fb5c540bb7888faec05670bd70a93e0593dcfb1 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 25 Nov 2015 22:38:29 +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. Built from https://develop.svn.wordpress.org/trunk@35742 git-svn-id: http://core.svn.wordpress.org/trunk@35706 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/user.php | 8 ++++++-- wp-admin/user-new.php | 7 +++++-- wp-includes/default-filters.php | 2 +- wp-includes/user.php | 8 +++++--- wp-includes/version.php | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index e855e2e17d..3d37bdf579 100644 --- a/wp-admin/includes/user.php +++ b/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/wp-admin/user-new.php b/wp-admin/user-new.php index 0f16b28b2a..ff0bffb840 100644 --- a/wp-admin/user-new.php +++ b/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/wp-includes/default-filters.php b/wp-includes/default-filters.php index 0cd9e5c6a6..1faa084cf7 100644 --- a/wp-includes/default-filters.php +++ b/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/wp-includes/user.php b/wp-includes/user.php index 65ea0eef65..32b0ec7463 100644 --- a/wp-includes/user.php +++ b/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 ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 9d2849f230..1e43baf300 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-beta4-35741'; +$wp_version = '4.4-beta4-35742'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.