From e7a203cdf21a9ec6a48fb06d4382482461c29a9f Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Mon, 17 Aug 2015 14:24:43 +0000 Subject: [PATCH] Passwords: Restore second parameter for `wp_new_user_notification()`. After [33023] users would always be notified, this restores previous behavior. Props markjaquith, ocean90. Fixes #33358. git-svn-id: https://develop.svn.wordpress.org/trunk@33620 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/user.php | 2 +- src/wp-admin/network/site-new.php | 2 +- src/wp-admin/network/site-users.php | 2 +- src/wp-admin/network/user-new.php | 2 +- src/wp-includes/pluggable.php | 13 ++++++++++--- src/wp-includes/user.php | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php index 3348e43559..132ea6d76c 100644 --- a/src/wp-admin/includes/user.php +++ b/src/wp-admin/includes/user.php @@ -176,7 +176,7 @@ function edit_user( $user_id = 0 ) { $user_id = wp_update_user( $user ); } else { $user_id = wp_insert_user( $user ); - wp_new_user_notification( $user_id ); + wp_new_user_notification( $user_id, 'both' ); } return $user_id; } diff --git a/src/wp-admin/network/site-new.php b/src/wp-admin/network/site-new.php index cf36617e47..8dec36cf02 100644 --- a/src/wp-admin/network/site-new.php +++ b/src/wp-admin/network/site-new.php @@ -79,7 +79,7 @@ if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) { if ( false === $user_id ) wp_die( __( 'There was an error creating the user.' ) ); else - wp_new_user_notification( $user_id, $password ); + wp_new_user_notification( $user_id, 'both' ); } $wpdb->hide_errors(); diff --git a/src/wp-admin/network/site-users.php b/src/wp-admin/network/site-users.php index 0fcead5992..0ab1771088 100644 --- a/src/wp-admin/network/site-users.php +++ b/src/wp-admin/network/site-users.php @@ -77,7 +77,7 @@ if ( $action ) { if ( false === $user_id ) { $update = 'err_new_dup'; } else { - wp_new_user_notification( $user_id, $password ); + wp_new_user_notification( $user_id, 'both' ); add_user_to_blog( $id, $user_id, $_POST['new_role'] ); $update = 'newuser'; } diff --git a/src/wp-admin/network/user-new.php b/src/wp-admin/network/user-new.php index ba8969788b..002e098dc1 100644 --- a/src/wp-admin/network/user-new.php +++ b/src/wp-admin/network/user-new.php @@ -51,7 +51,7 @@ if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) { if ( ! $user_id ) { $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) ); } else { - wp_new_user_notification( $user_id, $password ); + wp_new_user_notification( $user_id, 'both' ); wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) ); exit; } diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 655fc55b80..c4eb8cc566 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -1688,10 +1688,13 @@ if ( !function_exists('wp_new_user_notification') ) : * A new user registration notification is also sent to admin email. * * @since 2.0.0 + * @since 4.3.0 The `$plaintext_pass` parameter was changed to `$notify`. * - * @param int $user_id User ID. + * @param int $user_id User ID. + * @param string $notify Whether admin and user should be notified ('both') or + * only the admin ('admin' or empty). */ -function wp_new_user_notification($user_id) { +function wp_new_user_notification( $user_id, $notify = '' ) { global $wpdb; $user = get_userdata( $user_id ); @@ -1705,9 +1708,14 @@ function wp_new_user_notification($user_id) { @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message); + if ( 'admin' === $notify || empty( $notify ) ) { + return; + } + // Generate something random for a password reset key. $key = wp_generate_password( 20, false ); + /** This action is documented in wp-login.php */ do_action( 'retrieve_password_key', $user->user_login, $key ); // Now insert the key, hashed, into the DB. @@ -1725,7 +1733,6 @@ function wp_new_user_notification($user_id) { $message .= wp_login_url() . "\r\n"; wp_mail($user->user_email, sprintf(__('[%s] Your username and password info'), $blogname), $message); - } endif; diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 54b09ff9f9..1cd2db22e5 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -2619,7 +2619,7 @@ function register_new_user( $user_login, $user_email ) { update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag. - wp_new_user_notification( $user_id ); + wp_new_user_notification( $user_id, 'both' ); return $user_id; }