Skip to content

Commit daa3fe4

Browse files
committed
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
1 parent 6b37ee4 commit daa3fe4

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/wp-admin/includes/user.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,18 @@ function edit_user( $user_id = 0 ) {
176176
$user_id = wp_update_user( $user );
177177
} else {
178178
$user_id = wp_insert_user( $user );
179+
$notify = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin';
180+
179181
/**
180182
* Fires after a new user has been created.
181183
*
182184
* @since 4.4.0
183185
*
184-
* @param int $user_id ID of the newly created user.
186+
* @param int $user_id ID of the newly created user.
187+
* @param string $notify Type of notification that should happen. See {@see wp_send_new_user_notifications()}
188+
* for more information on possible values.
185189
*/
186-
do_action( 'edit_user_created_user', $user_id );
190+
do_action( 'edit_user_created_user', $user_id, $notify );
187191
}
188192
return $user_id;
189193
}

src/wp-admin/user-new.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@
368368
$new_user_email = $creating && isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '';
369369
$new_user_uri = $creating && isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : '';
370370
$new_user_role = $creating && isset( $_POST['role'] ) ? wp_unslash( $_POST['role'] ) : '';
371-
$new_user_send_password = $creating && isset( $_POST['send_password'] ) ? wp_unslash( $_POST['send_password'] ) : true;
371+
$new_user_send_notification = $creating && ! isset( $_POST['send_user_notification'] ) ? false : true;
372372
$new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unslash( $_POST['noconfirmation'] ) : '';
373373

374374
?>
@@ -418,7 +418,6 @@
418418
</button>
419419
<div style="display:none" id="pass-strength-result" aria-live="polite"></div>
420420
</div>
421-
<p><span class="description"><?php _e( 'A password reset link will be sent to the user via email.' ); ?></span></p>
422421
</td>
423422
</tr>
424423
<tr class="form-field form-required user-pass2-wrap hide-if-js">
@@ -436,6 +435,10 @@
436435
</label>
437436
</td>
438437
</tr>
438+
<tr>
439+
<th scope="row"><?php _e( 'Send User Notification' ) ?></th>
440+
<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>
441+
</tr>
439442
<?php } // !is_multisite ?>
440443
<tr class="form-field">
441444
<th scope="row"><label for="role"><?php _e('Role'); ?></label></th>

src/wp-includes/default-filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
358358
add_action( 'after_password_reset', 'wp_password_change_notification' );
359359
add_action( 'register_new_user', 'wp_send_new_user_notifications' );
360-
add_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );
360+
add_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );
361361

362362
// REST API actions.
363363
add_action( 'init', 'rest_api_init' );

src/wp-includes/user.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,10 +2198,12 @@ function register_new_user( $user_login, $user_email ) {
21982198
*
21992199
* @since 4.4.0
22002200
*
2201-
* @param int $user_id ID of the newly created user.
2201+
* @param int $user_id ID of the newly created user.
2202+
* @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty string
2203+
* (admin only), or 'both' (admin and user). Default 'both'.
22022204
*/
2203-
function wp_send_new_user_notifications( $user_id ) {
2204-
wp_new_user_notification( $user_id, null, 'both' );
2205+
function wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
2206+
wp_new_user_notification( $user_id, null, $notify );
22052207
}
22062208

22072209
/**

0 commit comments

Comments
 (0)