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
This commit is contained in:
Dominik Schilling 2015-11-25 22:38:29 +00:00
parent 7ce9772866
commit 9fb5c540bb
5 changed files with 18 additions and 9 deletions

View File

@ -176,14 +176,18 @@ function edit_user( $user_id = 0 ) {
$user_id = wp_update_user( $user ); $user_id = wp_update_user( $user );
} else { } else {
$user_id = wp_insert_user( $user ); $user_id = wp_insert_user( $user );
$notify = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin';
/** /**
* Fires after a new user has been created. * Fires after a new user has been created.
* *
* @since 4.4.0 * @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; return $user_id;
} }

View File

@ -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_email = $creating && isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '';
$new_user_uri = $creating && isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : ''; $new_user_uri = $creating && isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : '';
$new_user_role = $creating && isset( $_POST['role'] ) ? wp_unslash( $_POST['role'] ) : ''; $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'] ) : ''; $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
</button> </button>
<div style="display:none" id="pass-strength-result" aria-live="polite"></div> <div style="display:none" id="pass-strength-result" aria-live="polite"></div>
</div> </div>
<p><span class="description"><?php _e( 'A password reset link will be sent to the user via email.' ); ?></span></p>
</td> </td>
</tr> </tr>
<tr class="form-field form-required user-pass2-wrap hide-if-js"> <tr class="form-field form-required user-pass2-wrap hide-if-js">
@ -436,6 +435,10 @@ $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unsl
</label> </label>
</td> </td>
</tr> </tr>
<tr>
<th scope="row"><?php _e( 'Send User Notification' ) ?></th>
<td><label for="send_user_notification"><input type="checkbox" name="send_user_notification" id="send_user_notification" value="1" <?php checked( $new_user_send_notification ); ?> /> <?php _e( 'Send the new user an email about their account.' ); ?></label></td>
</tr>
<?php } // !is_multisite ?> <?php } // !is_multisite ?>
<tr class="form-field"> <tr class="form-field">
<th scope="row"><label for="role"><?php _e('Role'); ?></label></th> <th scope="row"><label for="role"><?php _e('Role'); ?></label></th>

View File

@ -357,7 +357,7 @@ add_action( 'comment_post', 'wp_new_comment_notify_moderator' );
add_action( 'comment_post', 'wp_new_comment_notify_postauthor' ); add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
add_action( 'after_password_reset', 'wp_password_change_notification' ); add_action( 'after_password_reset', 'wp_password_change_notification' );
add_action( 'register_new_user', 'wp_send_new_user_notifications' ); 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. // REST API actions.
add_action( 'init', 'rest_api_init' ); add_action( 'init', 'rest_api_init' );

View File

@ -2199,9 +2199,11 @@ function register_new_user( $user_login, $user_email ) {
* @since 4.4.0 * @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 ) { function wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
wp_new_user_notification( $user_id, null, 'both' ); wp_new_user_notification( $user_id, null, $notify );
} }
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.