5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage Administration |
6 * @subpackage Administration |
7 */ |
7 */ |
8 |
8 |
9 /** WordPress Administration Bootstrap */ |
9 /** WordPress Administration Bootstrap */ |
10 require_once( dirname( __FILE__ ) . '/admin.php' ); |
10 require_once __DIR__ . '/admin.php'; |
11 |
11 |
12 if ( is_multisite() ) { |
12 if ( is_multisite() ) { |
13 if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) ) { |
13 if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) ) { |
14 wp_die( |
14 wp_die( |
15 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
15 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
27 |
27 |
28 if ( is_multisite() ) { |
28 if ( is_multisite() ) { |
29 add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' ); |
29 add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' ); |
30 } |
30 } |
31 |
31 |
32 if ( isset( $_REQUEST['action'] ) && 'adduser' == $_REQUEST['action'] ) { |
32 if ( isset( $_REQUEST['action'] ) && 'adduser' === $_REQUEST['action'] ) { |
33 check_admin_referer( 'add-user', '_wpnonce_add-user' ); |
33 check_admin_referer( 'add-user', '_wpnonce_add-user' ); |
34 |
34 |
35 $user_details = null; |
35 $user_details = null; |
36 $user_email = wp_unslash( $_REQUEST['email'] ); |
36 $user_email = wp_unslash( $_REQUEST['email'] ); |
37 if ( false !== strpos( $user_email, '@' ) ) { |
37 if ( false !== strpos( $user_email, '@' ) ) { |
56 '<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>', |
56 '<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>', |
57 403 |
57 403 |
58 ); |
58 ); |
59 } |
59 } |
60 |
60 |
61 // Adding an existing user to this blog |
61 // Adding an existing user to this blog. |
62 $new_user_email = $user_details->user_email; |
62 $new_user_email = $user_details->user_email; |
63 $redirect = 'user-new.php'; |
63 $redirect = 'user-new.php'; |
64 $username = $user_details->user_login; |
64 $username = $user_details->user_login; |
65 $user_id = $user_details->ID; |
65 $user_id = $user_details->ID; |
66 if ( $username != null && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) { |
66 if ( null != $username && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) { |
67 $redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' ); |
67 $redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' ); |
68 } else { |
68 } else { |
69 if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) { |
69 if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) { |
70 $result = add_existing_user_to_blog( |
70 $result = add_existing_user_to_blog( |
71 array( |
71 array( |
103 * Fires immediately after a user is invited to join a site, but before the notification is sent. |
103 * Fires immediately after a user is invited to join a site, but before the notification is sent. |
104 * |
104 * |
105 * @since 4.4.0 |
105 * @since 4.4.0 |
106 * |
106 * |
107 * @param int $user_id The invited user's ID. |
107 * @param int $user_id The invited user's ID. |
108 * @param array $role The role of invited user. |
108 * @param array $role Array containing role information for the invited user. |
109 * @param string $newuser_key The key of the invitation. |
109 * @param string $newuser_key The key of the invitation. |
110 */ |
110 */ |
111 do_action( 'invite_user', $user_id, $role, $newuser_key ); |
111 do_action( 'invite_user', $user_id, $role, $newuser_key ); |
112 |
112 |
113 $switched_locale = switch_to_locale( get_user_locale( $user_details ) ); |
113 $switched_locale = switch_to_locale( get_user_locale( $user_details ) ); |
114 |
114 |
115 /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */ |
115 /* translators: 1: Site title, 2: Site URL, 3: User role, 4: Activation URL. */ |
116 $message = __( |
116 $message = __( |
117 'Hi, |
117 'Hi, |
118 |
118 |
119 You\'ve been invited to join \'%1$s\' at |
119 You\'ve been invited to join \'%1$s\' at |
120 %2$s with the role of %3$s. |
120 %2$s with the role of %3$s. |
121 |
121 |
122 Please click the following link to confirm the invite: |
122 Please click the following link to confirm the invite: |
123 %4$s' |
123 %4$s' |
124 ); |
124 ); |
125 |
125 |
126 /* translators: Joining confirmation notification email subject. %s: Site title */ |
126 wp_mail( |
127 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/" ) ) ); |
127 $new_user_email, |
|
128 sprintf( |
|
129 /* translators: Joining confirmation notification email subject. %s: Site title. */ |
|
130 __( '[%s] Joining Confirmation' ), |
|
131 wp_specialchars_decode( get_option( 'blogname' ) ) |
|
132 ), |
|
133 sprintf( |
|
134 $message, |
|
135 get_option( 'blogname' ), |
|
136 home_url(), |
|
137 wp_specialchars_decode( translate_user_role( $role['name'] ) ), |
|
138 home_url( "/newbloguser/$newuser_key/" ) |
|
139 ) |
|
140 ); |
128 |
141 |
129 if ( $switched_locale ) { |
142 if ( $switched_locale ) { |
130 restore_previous_locale(); |
143 restore_previous_locale(); |
131 } |
144 } |
132 |
145 |
133 $redirect = add_query_arg( array( 'update' => 'add' ), 'user-new.php' ); |
146 $redirect = add_query_arg( array( 'update' => 'add' ), 'user-new.php' ); |
134 } |
147 } |
135 } |
148 } |
136 wp_redirect( $redirect ); |
149 wp_redirect( $redirect ); |
137 die(); |
150 die(); |
138 } elseif ( isset( $_REQUEST['action'] ) && 'createuser' == $_REQUEST['action'] ) { |
151 } elseif ( isset( $_REQUEST['action'] ) && 'createuser' === $_REQUEST['action'] ) { |
139 check_admin_referer( 'create-user', '_wpnonce_create-user' ); |
152 check_admin_referer( 'create-user', '_wpnonce_create-user' ); |
140 |
153 |
141 if ( ! current_user_can( 'create_users' ) ) { |
154 if ( ! current_user_can( 'create_users' ) ) { |
142 wp_die( |
155 wp_die( |
143 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
156 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
159 } |
172 } |
160 wp_redirect( $redirect ); |
173 wp_redirect( $redirect ); |
161 die(); |
174 die(); |
162 } |
175 } |
163 } else { |
176 } else { |
164 // Adding a new user to this site |
177 // Adding a new user to this site. |
165 $new_user_email = wp_unslash( $_REQUEST['email'] ); |
178 $new_user_email = wp_unslash( $_REQUEST['email'] ); |
166 $user_details = wpmu_validate_user_signup( $_REQUEST['user_login'], $new_user_email ); |
179 $user_details = wpmu_validate_user_signup( $_REQUEST['user_login'], $new_user_email ); |
167 if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) { |
180 if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) { |
168 $add_user_errors = $user_details['errors']; |
181 $add_user_errors = $user_details['errors']; |
169 } else { |
182 } else { |
170 /** This filter is documented in wp-includes/user.php */ |
183 /** This filter is documented in wp-includes/user.php */ |
171 $new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) ); |
184 $new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) ); |
172 if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) { |
185 if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) { |
173 add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email |
186 add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email. |
174 add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email |
187 add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email. |
175 } |
188 } |
176 wpmu_signup_user( |
189 wpmu_signup_user( |
177 $new_user_login, |
190 $new_user_login, |
178 $new_user_email, |
191 $new_user_email, |
179 array( |
192 array( |
238 get_current_screen()->add_help_tab( |
251 get_current_screen()->add_help_tab( |
239 array( |
252 array( |
240 'id' => 'user-roles', |
253 'id' => 'user-roles', |
241 'title' => __( 'User Roles' ), |
254 'title' => __( 'User Roles' ), |
242 'content' => '<p>' . __( 'Here is a basic overview of the different user roles and the permissions associated with each one:' ) . '</p>' . |
255 'content' => '<p>' . __( 'Here is a basic overview of the different user roles and the permissions associated with each one:' ) . '</p>' . |
243 '<ul>' . |
256 '<ul>' . |
244 '<li>' . __( 'Subscribers can read comments/comment/receive newsletters, etc. but cannot create regular site content.' ) . '</li>' . |
257 '<li>' . __( 'Subscribers can read comments/comment/receive newsletters, etc. but cannot create regular site content.' ) . '</li>' . |
245 '<li>' . __( 'Contributors can write and manage their posts but not publish posts or upload media files.' ) . '</li>' . |
258 '<li>' . __( 'Contributors can write and manage their posts but not publish posts or upload media files.' ) . '</li>' . |
246 '<li>' . __( 'Authors can publish and manage their own posts, and are able to upload files.' ) . '</li>' . |
259 '<li>' . __( 'Authors can publish and manage their own posts, and are able to upload files.' ) . '</li>' . |
247 '<li>' . __( 'Editors can publish posts, manage posts as well as manage other people’s posts, etc.' ) . '</li>' . |
260 '<li>' . __( 'Editors can publish posts, manage posts as well as manage other people’s posts, etc.' ) . '</li>' . |
248 '<li>' . __( 'Administrators have access to all the administration features.' ) . '</li>' . |
261 '<li>' . __( 'Administrators have access to all the administration features.' ) . '</li>' . |
249 '</ul>', |
262 '</ul>', |
250 ) |
263 ) |
251 ); |
264 ); |
252 |
265 |
253 get_current_screen()->set_help_sidebar( |
266 get_current_screen()->set_help_sidebar( |
254 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
267 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
255 '<p>' . __( '<a href="https://codex.wordpress.org/Users_Add_New_Screen">Documentation on Adding New Users</a>' ) . '</p>' . |
268 '<p>' . __( '<a href="https://wordpress.org/support/article/users-add-new-screen/">Documentation on Adding New Users</a>' ) . '</p>' . |
256 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
269 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
257 ); |
270 ); |
258 |
271 |
259 wp_enqueue_script( 'wp-ajax-response' ); |
272 wp_enqueue_script( 'wp-ajax-response' ); |
260 wp_enqueue_script( 'user-profile' ); |
273 wp_enqueue_script( 'user-profile' ); |
291 break; |
304 break; |
292 case 'add': |
305 case 'add': |
293 $messages[] = __( 'Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.' ); |
306 $messages[] = __( 'Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.' ); |
294 break; |
307 break; |
295 case 'addnoconfirmation': |
308 case 'addnoconfirmation': |
296 if ( empty( $edit_link ) ) { |
309 $message = __( 'User has been added to your site.' ); |
297 $messages[] = __( 'User has been added to your site.' ); |
310 |
298 } else { |
311 if ( $edit_link ) { |
299 /* translators: %s: edit page url */ |
312 $message .= sprintf( ' <a href="%s">%s</a>', $edit_link, __( 'Edit user' ) ); |
300 $messages[] = sprintf( __( 'User has been added to your site. <a href="%s">Edit user</a>' ), $edit_link ); |
|
301 } |
313 } |
|
314 |
|
315 $messages[] = $message; |
302 break; |
316 break; |
303 case 'addexisting': |
317 case 'addexisting': |
304 $messages[] = __( 'That user is already a member of this site.' ); |
318 $messages[] = __( 'That user is already a member of this site.' ); |
305 break; |
319 break; |
306 case 'could_not_add': |
320 case 'could_not_add': |
430 do_action( 'user_new_form', 'add-existing-user' ); |
444 do_action( 'user_new_form', 'add-existing-user' ); |
431 ?> |
445 ?> |
432 <?php submit_button( __( 'Add Existing User' ), 'primary', 'adduser', true, array( 'id' => 'addusersub' ) ); ?> |
446 <?php submit_button( __( 'Add Existing User' ), 'primary', 'adduser', true, array( 'id' => 'addusersub' ) ); ?> |
433 </form> |
447 </form> |
434 <?php |
448 <?php |
435 } // is_multisite() |
449 } // End if is_multisite(). |
436 |
450 |
437 if ( current_user_can( 'create_users' ) ) { |
451 if ( current_user_can( 'create_users' ) ) { |
438 if ( $do_both ) { |
452 if ( $do_both ) { |
439 echo '<h2 id="create-new-user">' . __( 'Add New User' ) . '</h2>'; |
453 echo '<h2 id="create-new-user">' . __( 'Add New User' ) . '</h2>'; |
440 } |
454 } |
482 </tr> |
496 </tr> |
483 <tr class="form-field"> |
497 <tr class="form-field"> |
484 <th scope="row"><label for="url"><?php _e( 'Website' ); ?></label></th> |
498 <th scope="row"><label for="url"><?php _e( 'Website' ); ?></label></th> |
485 <td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td> |
499 <td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td> |
486 </tr> |
500 </tr> |
|
501 <?php |
|
502 $languages = get_available_languages(); |
|
503 if ( $languages ) : |
|
504 ?> |
|
505 <tr class="form-field user-language-wrap"> |
|
506 <th scope="row"> |
|
507 <label for="locale"> |
|
508 <?php /* translators: The user language selection field label. */ ?> |
|
509 <?php _e( 'Language' ); ?><span class="dashicons dashicons-translation" aria-hidden="true"></span> |
|
510 </label> |
|
511 </th> |
|
512 <td> |
|
513 <?php |
|
514 wp_dropdown_languages( |
|
515 array( |
|
516 'name' => 'locale', |
|
517 'id' => 'locale', |
|
518 'selected' => 'site-default', |
|
519 'languages' => $languages, |
|
520 'show_available_translations' => false, |
|
521 'show_option_site_default' => true, |
|
522 ) |
|
523 ); |
|
524 ?> |
|
525 </td> |
|
526 </tr> |
|
527 <?php endif; ?> |
487 <tr class="form-field form-required user-pass1-wrap"> |
528 <tr class="form-field form-required user-pass1-wrap"> |
488 <th scope="row"> |
529 <th scope="row"> |
489 <label for="pass1"> |
530 <label for="pass1"> |
490 <?php _e( 'Password' ); ?> |
531 <?php _e( 'Password' ); ?> |
491 <span class="description hide-if-js"><?php _e( '(required)' ); ?></span> |
532 <span class="description hide-if-js"><?php _e( '(required)' ); ?></span> |
531 <td> |
572 <td> |
532 <input type="checkbox" name="send_user_notification" id="send_user_notification" value="1" <?php checked( $new_user_send_notification ); ?> /> |
573 <input type="checkbox" name="send_user_notification" id="send_user_notification" value="1" <?php checked( $new_user_send_notification ); ?> /> |
533 <label for="send_user_notification"><?php _e( 'Send the new user an email about their account.' ); ?></label> |
574 <label for="send_user_notification"><?php _e( 'Send the new user an email about their account.' ); ?></label> |
534 </td> |
575 </td> |
535 </tr> |
576 </tr> |
536 <?php } // !is_multisite ?> |
577 <?php } // End if ! is_multisite(). ?> |
|
578 <?php if ( current_user_can( 'promote_users' ) ) { ?> |
537 <tr class="form-field"> |
579 <tr class="form-field"> |
538 <th scope="row"><label for="role"><?php _e( 'Role' ); ?></label></th> |
580 <th scope="row"><label for="role"><?php _e( 'Role' ); ?></label></th> |
539 <td><select name="role" id="role"> |
581 <td><select name="role" id="role"> |
540 <?php |
582 <?php |
541 if ( ! $new_user_role ) { |
583 if ( ! $new_user_role ) { |