Ticket #42132: 42132.3.diff
File 42132.3.diff, 6.2 KB (added by , 6 years ago) |
---|
-
src/wp-admin/user-new.php
diff --git a/src/wp-admin/user-new.php b/src/wp-admin/user-new.php index 91ba0ace58..b54230e746 100644
a b if ( is_multisite() ) { 29 29 add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' ); 30 30 } 31 31 32 // Add a user from the network to this website. 32 33 if ( isset( $_REQUEST['action'] ) && 'adduser' == $_REQUEST['action'] ) { 33 34 check_admin_referer( 'add-user', '_wpnonce_add-user' ); 34 35 35 $user _details= null;36 $ user_email= wp_unslash( $_REQUEST['email'] );37 if ( false !== strpos( $ user_email, '@' ) ) {38 $user _details = get_user_by( 'email', $user_email );36 $user = null; 37 $request_user_email = wp_unslash( $_REQUEST['email'] ); 38 if ( false !== strpos( $request_user_email, '@' ) ) { 39 $user = get_user_by( 'email', $request_user_email ); 39 40 } else { 40 41 if ( current_user_can( 'manage_network_users' ) ) { 41 $user _details = get_user_by( 'login', $user_email );42 $user = get_user_by( 'login', $request_user_email ); 42 43 } else { 43 44 wp_redirect( add_query_arg( array( 'update' => 'enter_email' ), 'user-new.php' ) ); 44 45 die(); 45 46 } 46 47 } 47 48 48 if ( ! $user _details) {49 if ( ! $user instanceof WP_User ) { 49 50 wp_redirect( add_query_arg( array( 'update' => 'does_not_exist' ), 'user-new.php' ) ); 50 51 die(); 51 52 } 52 53 53 if ( ! current_user_can( 'promote_user', $user _details->ID ) ) {54 if ( ! current_user_can( 'promote_user', $user->ID ) ) { 54 55 wp_die( 55 56 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . 56 57 '<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>', … … if ( isset( $_REQUEST['action'] ) && 'adduser' == $_REQUEST['action'] ) { 58 59 ); 59 60 } 60 61 61 // Adding an existing user to this blog62 $ new_user_email = $user_details->user_email;63 $ redirect = 'user-new.php';64 $ username = $user_details->user_login;65 $user_id = $user_details->ID; 66 if ( $username != null && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) {62 $redirect = 'user-new.php'; 63 $username = $user->user_login; 64 $user_id = $user->ID; 65 $blog_title = wp_specialchars_decode( get_option( 'blogname' ) ); 66 67 if ( $username !== null && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) { 67 68 $redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' ); 68 69 } else { 69 70 if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) { … … if ( isset( $_REQUEST['action'] ) && 'adduser' == $_REQUEST['action'] ) { 89 90 add_option( 90 91 'new_user_' . $newuser_key, array( 91 92 'user_id' => $user_id, 92 'email' => $user _details->user_email,93 'email' => $user->user_email, 93 94 'role' => $_REQUEST['role'], 94 95 ) 95 96 ); … … if ( isset( $_REQUEST['action'] ) && 'adduser' == $_REQUEST['action'] ) { 108 109 */ 109 110 do_action( 'invite_user', $user_id, $role, $newuser_key ); 110 111 111 $switched_locale = switch_to_locale( get_user_locale( $user _details) );112 $switched_locale = switch_to_locale( get_user_locale( $user ) ); 112 113 113 /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */ 114 $message = __( 115 'Hi, 114 /* translators: User invite notification. Do not translate SITENAME, SITEURL, ROLE, ACTIVATIONURL: those are placeholders. */ 115 $new_user_text = __( 'Hi, 116 116 117 You\'ve been invited to join \'%1$s\'at118 %2$s with the role of %3$s.117 You\'ve been invited to join ###SITENAME### at 118 ###SITEURL### with the role of ###ROLE###. 119 119 120 120 Please click the following link to confirm the invite: 121 %4$s' 121 ###ACTIVATIONURL###' ); 122 123 $new_user_email = array( 124 'to' => $user->user_email, 125 /* translators: User invite notification email subject. 1: Site name */ 126 'subject' => __( '[%s] Joining confirmation' ), 127 'message' => $new_user_text, 128 ); 129 130 /** 131 * Filters the contents of the email sent when an user is invited. 132 * 133 * @since 5.0 134 * 135 * @param array $new_user_email { 136 * Used to build wp_mail(). 137 * @type string $to The intended recipients. Add emails in a comma separated string. 138 * @type string $subject The subject of the email. 139 * @type string $message The content of the email. 140 * The following strings have a special meaning and will get replaced dynamically: 141 * - ###SITENAME### The name of the site. 142 * - ###SITEURL### The URL of the site. 143 * - ###ROLE### The user's role. 144 * - ###PASSWORD### The user's password. 145 * - ###ACTIVATIONURL### The user's activation URL. 146 * @type string $headers Headers. Add headers in a newline (\r\n) separated string. 147 * } 148 * @param WP_User $user_id The invited user object. 149 * @param array $role The role of invited user. 150 * @param string $newuser_key The key of the invitation. 151 * @param string $blog_title The site title. 152 * 153 */ 154 $new_user_email = apply_filters( 'new_user_email', $new_user_email, $user, $role, $newuser_key, $blog_title ); 155 156 $new_user_email['message'] = str_replace( 157 array( 158 '###SITENAME###', 159 '###SITEURL###', 160 '###ROLE###', 161 '###ACTIVATIONURL###', 162 ), 163 array( 164 $blog_title, 165 home_url(), 166 wp_specialchars_decode( translate_user_role( $role['name'] ) ), 167 home_url( "/newbloguser/$newuser_key/" ) 168 ), 169 $new_user_email['message'] 122 170 ); 123 wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), sprintf( $message, get_option( 'blogname' ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ), home_url( "/newbloguser/$newuser_key/" ) ) ); 171 172 wp_mail( $new_user_email['to'], sprintf( $new_user_email['subject'], $blog_title ), $new_user_email['message'], $new_blog_email['headers'] ); 124 173 125 174 if ( $switched_locale ) { 126 175 restore_previous_locale(); … … Please click the following link to confirm the invite: 131 180 } 132 181 wp_redirect( $redirect ); 133 182 die(); 183 184 // Create a completely new user. 134 185 } elseif ( isset( $_REQUEST['action'] ) && 'createuser' == $_REQUEST['action'] ) { 135 186 check_admin_referer( 'create-user', '_wpnonce_create-user' ); 136 187