110 wp_redirect( $redirect ); |
110 wp_redirect( $redirect ); |
111 exit; |
111 exit; |
112 } |
112 } |
113 |
113 |
114 $editable_roles = get_editable_roles(); |
114 $editable_roles = get_editable_roles(); |
115 $role = false; |
115 $role = $_REQUEST['new_role']; |
116 if ( ! empty( $_REQUEST['new_role2'] ) ) { |
116 |
117 $role = $_REQUEST['new_role2']; |
117 // Mocking the `none` role so we are able to save it to the database |
118 } elseif ( ! empty( $_REQUEST['new_role'] ) ) { |
118 $editable_roles['none'] = array( |
119 $role = $_REQUEST['new_role']; |
119 'name' => __( '— No role for this site —' ), |
120 } |
120 ); |
121 |
121 |
122 if ( ! $role || empty( $editable_roles[ $role ] ) ) { |
122 if ( ! $role || empty( $editable_roles[ $role ] ) ) { |
123 wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 ); |
123 wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 ); |
|
124 } |
|
125 |
|
126 if ( 'none' === $role ) { |
|
127 $role = ''; |
124 } |
128 } |
125 |
129 |
126 $userids = $_REQUEST['users']; |
130 $userids = $_REQUEST['users']; |
127 $update = 'promote'; |
131 $update = 'promote'; |
128 foreach ( $userids as $id ) { |
132 foreach ( $userids as $id ) { |
211 $redirect |
215 $redirect |
212 ); |
216 ); |
213 wp_redirect( $redirect ); |
217 wp_redirect( $redirect ); |
214 exit; |
218 exit; |
215 |
219 |
|
220 case 'resetpassword': |
|
221 check_admin_referer( 'bulk-users' ); |
|
222 if ( ! current_user_can( 'edit_users' ) ) { |
|
223 $errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to edit users.' ) ); |
|
224 } |
|
225 if ( empty( $_REQUEST['users'] ) ) { |
|
226 wp_redirect( $redirect ); |
|
227 exit(); |
|
228 } |
|
229 $userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
|
230 |
|
231 $reset_count = 0; |
|
232 |
|
233 foreach ( $userids as $id ) { |
|
234 if ( ! current_user_can( 'edit_user', $id ) ) { |
|
235 wp_die( __( 'Sorry, you are not allowed to edit this user.' ) ); |
|
236 } |
|
237 |
|
238 if ( $id === $current_user->ID ) { |
|
239 $update = 'err_admin_reset'; |
|
240 continue; |
|
241 } |
|
242 |
|
243 // Send the password reset link. |
|
244 $user = get_userdata( $id ); |
|
245 if ( retrieve_password( $user->user_login ) ) { |
|
246 ++$reset_count; |
|
247 } |
|
248 } |
|
249 |
|
250 $redirect = add_query_arg( |
|
251 array( |
|
252 'reset_count' => $reset_count, |
|
253 'update' => 'resetpassword', |
|
254 ), |
|
255 $redirect |
|
256 ); |
|
257 wp_redirect( $redirect ); |
|
258 exit; |
|
259 |
216 case 'delete': |
260 case 'delete': |
217 if ( is_multisite() ) { |
261 if ( is_multisite() ) { |
218 wp_die( __( 'User deletion is not allowed from this screen.' ), 400 ); |
262 wp_die( __( 'User deletion is not allowed from this screen.' ), 400 ); |
219 } |
263 } |
220 |
264 |
228 if ( ! current_user_can( 'delete_users' ) ) { |
272 if ( ! current_user_can( 'delete_users' ) ) { |
229 $errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to delete users.' ) ); |
273 $errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to delete users.' ) ); |
230 } |
274 } |
231 |
275 |
232 if ( empty( $_REQUEST['users'] ) ) { |
276 if ( empty( $_REQUEST['users'] ) ) { |
233 $userids = array( intval( $_REQUEST['user'] ) ); |
277 $userids = array( (int) $_REQUEST['user'] ); |
234 } else { |
278 } else { |
235 $userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
279 $userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
236 } |
280 } |
237 |
281 |
238 $all_userids = $userids; |
282 $all_userids = $userids; |
399 if ( ! current_user_can( 'remove_users' ) ) { |
443 if ( ! current_user_can( 'remove_users' ) ) { |
400 $error = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to remove users.' ) ); |
444 $error = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to remove users.' ) ); |
401 } |
445 } |
402 |
446 |
403 if ( empty( $_REQUEST['users'] ) ) { |
447 if ( empty( $_REQUEST['users'] ) ) { |
404 $userids = array( intval( $_REQUEST['user'] ) ); |
448 $userids = array( (int) $_REQUEST['user'] ); |
405 } else { |
449 } else { |
406 $userids = $_REQUEST['users']; |
450 $userids = $_REQUEST['users']; |
407 } |
451 } |
408 |
452 |
409 require_once ABSPATH . 'wp-admin/admin-header.php'; |
453 require_once ABSPATH . 'wp-admin/admin-header.php'; |
509 ); |
553 ); |
510 } |
554 } |
511 |
555 |
512 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . $message . '</p></div>'; |
556 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . $message . '</p></div>'; |
513 break; |
557 break; |
|
558 case 'resetpassword': |
|
559 $reset_count = isset( $_GET['reset_count'] ) ? (int) $_GET['reset_count'] : 0; |
|
560 if ( 1 === $reset_count ) { |
|
561 $message = __( 'Password reset link sent.' ); |
|
562 } else { |
|
563 /* translators: %s: Number of users. */ |
|
564 $message = _n( 'Password reset links sent to %s user.', 'Password reset links sent to %s users.', $reset_count ); |
|
565 } |
|
566 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $reset_count ) ) . '</p></div>'; |
|
567 break; |
514 case 'promote': |
568 case 'promote': |
515 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>'; |
569 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>'; |
516 break; |
570 break; |
517 case 'err_admin_role': |
571 case 'err_admin_role': |
518 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'The current user’s role must have user editing capabilities.' ) . '</p></div>'; |
572 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'The current user’s role must have user editing capabilities.' ) . '</p></div>'; |
561 </h1> |
615 </h1> |
562 |
616 |
563 <?php |
617 <?php |
564 if ( current_user_can( 'create_users' ) ) { |
618 if ( current_user_can( 'create_users' ) ) { |
565 ?> |
619 ?> |
566 <a href="<?php echo admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> |
620 <a href="<?php echo esc_url( admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> |
567 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> |
621 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> |
568 <a href="<?php echo admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> |
622 <a href="<?php echo esc_url( admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> |
569 <?php |
623 <?php |
570 } |
624 } |
571 |
625 |
572 if ( strlen( $usersearch ) ) { |
626 if ( strlen( $usersearch ) ) { |
573 /* translators: %s: Search query. */ |
627 echo '<span class="subtitle">'; |
574 printf( '<span class="subtitle">' . __( 'Search results for “%s”' ) . '</span>', esc_html( $usersearch ) ); |
628 printf( |
|
629 /* translators: %s: Search query. */ |
|
630 __( 'Search results for: %s' ), |
|
631 '<strong>' . esc_html( $usersearch ) . '</strong>' |
|
632 ); |
|
633 echo '</span>'; |
575 } |
634 } |
576 ?> |
635 ?> |
577 |
636 |
578 <hr class="wp-header-end"> |
637 <hr class="wp-header-end"> |
579 |
638 |