22 public function ajax_user_can() { |
22 public function ajax_user_can() { |
23 return current_user_can( 'manage_network_users' ); |
23 return current_user_can( 'manage_network_users' ); |
24 } |
24 } |
25 |
25 |
26 /** |
26 /** |
|
27 * @global string $mode List table view mode. |
27 * @global string $usersearch |
28 * @global string $usersearch |
28 * @global string $role |
29 * @global string $role |
29 * @global string $mode |
|
30 */ |
30 */ |
31 public function prepare_items() { |
31 public function prepare_items() { |
32 global $usersearch, $role, $mode; |
32 global $mode, $usersearch, $role; |
|
33 |
|
34 if ( ! empty( $_REQUEST['mode'] ) ) { |
|
35 $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list'; |
|
36 set_user_setting( 'network_users_list_mode', $mode ); |
|
37 } else { |
|
38 $mode = get_user_setting( 'network_users_list_mode', 'list' ); |
|
39 } |
33 |
40 |
34 $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; |
41 $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; |
35 |
42 |
36 $users_per_page = $this->get_items_per_page( 'users_network_per_page' ); |
43 $users_per_page = $this->get_items_per_page( 'users_network_per_page' ); |
37 |
44 |
52 } elseif ( '' !== $args['search'] ) { |
59 } elseif ( '' !== $args['search'] ) { |
53 $args['search'] = trim( $args['search'], '*' ); |
60 $args['search'] = trim( $args['search'], '*' ); |
54 $args['search'] = '*' . $args['search'] . '*'; |
61 $args['search'] = '*' . $args['search'] . '*'; |
55 } |
62 } |
56 |
63 |
57 if ( $role === 'super' ) { |
64 if ( 'super' === $role ) { |
58 $args['login__in'] = get_super_admins(); |
65 $args['login__in'] = get_super_admins(); |
59 } |
66 } |
60 |
67 |
61 /* |
68 /* |
62 * If the network is large and a search is not being performed, |
69 * If the network is large and a search is not being performed, |
63 * show only the latest users with no paging in order to avoid |
70 * show only the latest users with no paging in order to avoid |
64 * expensive count queries. |
71 * expensive count queries. |
65 */ |
72 */ |
66 if ( ! $usersearch && wp_is_large_network( 'users' ) ) { |
73 if ( ! $usersearch && wp_is_large_network( 'users' ) ) { |
67 if ( ! isset( $_REQUEST['orderby'] ) ) { |
74 if ( ! isset( $_REQUEST['orderby'] ) ) { |
68 $_GET['orderby'] = $_REQUEST['orderby'] = 'id'; |
75 $_GET['orderby'] = 'id'; |
|
76 $_REQUEST['orderby'] = 'id'; |
69 } |
77 } |
70 if ( ! isset( $_REQUEST['order'] ) ) { |
78 if ( ! isset( $_REQUEST['order'] ) ) { |
71 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
79 $_GET['order'] = 'DESC'; |
|
80 $_REQUEST['order'] = 'DESC'; |
72 } |
81 } |
73 $args['count_total'] = false; |
82 $args['count_total'] = false; |
74 } |
83 } |
75 |
84 |
76 if ( isset( $_REQUEST['orderby'] ) ) { |
85 if ( isset( $_REQUEST['orderby'] ) ) { |
79 |
88 |
80 if ( isset( $_REQUEST['order'] ) ) { |
89 if ( isset( $_REQUEST['order'] ) ) { |
81 $args['order'] = $_REQUEST['order']; |
90 $args['order'] = $_REQUEST['order']; |
82 } |
91 } |
83 |
92 |
84 if ( ! empty( $_REQUEST['mode'] ) ) { |
|
85 $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; |
|
86 set_user_setting( 'network_users_list_mode', $mode ); |
|
87 } else { |
|
88 $mode = get_user_setting( 'network_users_list_mode', 'list' ); |
|
89 } |
|
90 |
|
91 /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ |
93 /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ |
92 $args = apply_filters( 'users_list_table_query_args', $args ); |
94 $args = apply_filters( 'users_list_table_query_args', $args ); |
93 |
95 |
94 // Query the user IDs for this page |
96 // Query the user IDs for this page. |
95 $wp_user_search = new WP_User_Query( $args ); |
97 $wp_user_search = new WP_User_Query( $args ); |
96 |
98 |
97 $this->items = $wp_user_search->get_results(); |
99 $this->items = $wp_user_search->get_results(); |
98 |
100 |
99 $this->set_pagination_args( |
101 $this->set_pagination_args( |
110 protected function get_bulk_actions() { |
112 protected function get_bulk_actions() { |
111 $actions = array(); |
113 $actions = array(); |
112 if ( current_user_can( 'delete_users' ) ) { |
114 if ( current_user_can( 'delete_users' ) ) { |
113 $actions['delete'] = __( 'Delete' ); |
115 $actions['delete'] = __( 'Delete' ); |
114 } |
116 } |
115 $actions['spam'] = _x( 'Mark as Spam', 'user' ); |
117 $actions['spam'] = _x( 'Mark as spam', 'user' ); |
116 $actions['notspam'] = _x( 'Not Spam', 'user' ); |
118 $actions['notspam'] = _x( 'Not spam', 'user' ); |
117 |
119 |
118 return $actions; |
120 return $actions; |
119 } |
121 } |
120 |
122 |
121 /** |
123 /** |
133 |
135 |
134 $total_users = get_user_count(); |
136 $total_users = get_user_count(); |
135 $super_admins = get_super_admins(); |
137 $super_admins = get_super_admins(); |
136 $total_admins = count( $super_admins ); |
138 $total_admins = count( $super_admins ); |
137 |
139 |
138 $current_link_attributes = $role !== 'super' ? ' class="current" aria-current="page"' : ''; |
140 $current_link_attributes = 'super' !== $role ? ' class="current" aria-current="page"' : ''; |
139 $role_links = array(); |
141 $role_links = array(); |
140 $role_links['all'] = "<a href='" . network_admin_url( 'users.php' ) . "'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; |
142 $role_links['all'] = sprintf( |
141 $current_link_attributes = $role === 'super' ? ' class="current" aria-current="page"' : ''; |
143 '<a href="%s"%s>%s</a>', |
142 $role_links['super'] = "<a href='" . network_admin_url( 'users.php?role=super' ) . "'$current_link_attributes>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>'; |
144 network_admin_url( 'users.php' ), |
|
145 $current_link_attributes, |
|
146 sprintf( |
|
147 /* translators: Number of users. */ |
|
148 _nx( |
|
149 'All <span class="count">(%s)</span>', |
|
150 'All <span class="count">(%s)</span>', |
|
151 $total_users, |
|
152 'users' |
|
153 ), |
|
154 number_format_i18n( $total_users ) |
|
155 ) |
|
156 ); |
|
157 $current_link_attributes = 'super' === $role ? ' class="current" aria-current="page"' : ''; |
|
158 $role_links['super'] = sprintf( |
|
159 '<a href="%s"%s>%s</a>', |
|
160 network_admin_url( 'users.php?role=super' ), |
|
161 $current_link_attributes, |
|
162 sprintf( |
|
163 /* translators: Number of users. */ |
|
164 _n( |
|
165 'Super Admin <span class="count">(%s)</span>', |
|
166 'Super Admins <span class="count">(%s)</span>', |
|
167 $total_admins |
|
168 ), |
|
169 number_format_i18n( $total_admins ) |
|
170 ) |
|
171 ); |
143 |
172 |
144 return $role_links; |
173 return $role_links; |
145 } |
174 } |
146 |
175 |
147 /** |
176 /** |
204 public function column_cb( $user ) { |
233 public function column_cb( $user ) { |
205 if ( is_super_admin( $user->ID ) ) { |
234 if ( is_super_admin( $user->ID ) ) { |
206 return; |
235 return; |
207 } |
236 } |
208 ?> |
237 ?> |
209 <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label> |
238 <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"> |
|
239 <?php |
|
240 /* translators: %s: User login. */ |
|
241 printf( __( 'Select %s' ), $user->user_login ); |
|
242 ?> |
|
243 </label> |
210 <input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" /> |
244 <input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" /> |
211 <?php |
245 <?php |
212 } |
246 } |
213 |
247 |
214 /** |
248 /** |
335 foreach ( $blogs as $val ) { |
369 foreach ( $blogs as $val ) { |
336 if ( ! can_edit_network( $val->site_id ) ) { |
370 if ( ! can_edit_network( $val->site_id ) ) { |
337 continue; |
371 continue; |
338 } |
372 } |
339 |
373 |
340 $path = ( $val->path === '/' ) ? '' : $val->path; |
374 $path = ( '/' === $val->path ) ? '' : $val->path; |
341 $site_classes = array( 'site-' . $val->site_id ); |
375 $site_classes = array( 'site-' . $val->site_id ); |
342 /** |
376 /** |
343 * Filters the span class for a site listing on the mulisite user list table. |
377 * Filters the span class for a site listing on the mulisite user list table. |
344 * |
378 * |
345 * @since 5.2.0 |
379 * @since 5.2.0 |
346 * |
380 * |
347 * @param array $site_classes Class used within the span tag. Default "site-#" with the site's network ID. |
381 * @param string[] $site_classes Array of class names used within the span tag. Default "site-#" with the site's network ID. |
348 * @param int $site_id Site ID. |
382 * @param int $site_id Site ID. |
349 * @param int $network_id Network ID. |
383 * @param int $network_id Network ID. |
350 * @param object $user WP_User object. |
384 * @param WP_User $user WP_User object. |
351 */ |
385 */ |
352 $site_classes = apply_filters( 'ms_user_list_site_class', $site_classes, $val->userblog_id, $val->site_id, $user ); |
386 $site_classes = apply_filters( 'ms_user_list_site_class', $site_classes, $val->userblog_id, $val->site_id, $user ); |
353 if ( is_array( $site_classes ) && ! empty( $site_classes ) ) { |
387 if ( is_array( $site_classes ) && ! empty( $site_classes ) ) { |
354 $site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) ); |
388 $site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) ); |
355 echo '<span class="' . esc_attr( implode( ' ', $site_classes ) ) . '">'; |
389 echo '<span class="' . esc_attr( implode( ' ', $site_classes ) ) . '">'; |
360 echo ' <small class="row-actions">'; |
394 echo ' <small class="row-actions">'; |
361 $actions = array(); |
395 $actions = array(); |
362 $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>'; |
396 $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>'; |
363 |
397 |
364 $class = ''; |
398 $class = ''; |
365 if ( $val->spam == 1 ) { |
399 if ( 1 == $val->spam ) { |
366 $class .= 'site-spammed '; |
400 $class .= 'site-spammed '; |
367 } |
401 } |
368 if ( $val->mature == 1 ) { |
402 if ( 1 == $val->mature ) { |
369 $class .= 'site-mature '; |
403 $class .= 'site-mature '; |
370 } |
404 } |
371 if ( $val->deleted == 1 ) { |
405 if ( 1 == $val->deleted ) { |
372 $class .= 'site-deleted '; |
406 $class .= 'site-deleted '; |
373 } |
407 } |
374 if ( $val->archived == 1 ) { |
408 if ( 1 == $val->archived ) { |
375 $class .= 'site-archived '; |
409 $class .= 'site-archived '; |
376 } |
410 } |
377 |
411 |
378 $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>'; |
412 $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>'; |
379 |
413 |
386 * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'View'. |
420 * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'View'. |
387 * @param int $userblog_id The site ID. |
421 * @param int $userblog_id The site ID. |
388 */ |
422 */ |
389 $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); |
423 $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); |
390 |
424 |
391 $i = 0; |
|
392 $action_count = count( $actions ); |
425 $action_count = count( $actions ); |
|
426 |
|
427 $i = 0; |
|
428 |
393 foreach ( $actions as $action => $link ) { |
429 foreach ( $actions as $action => $link ) { |
394 ++$i; |
430 ++$i; |
395 $sep = ( $i == $action_count ) ? '' : ' | '; |
431 |
|
432 $sep = ( $i < $action_count ) ? ' | ' : ''; |
|
433 |
396 echo "<span class='$action'>$link$sep</span>"; |
434 echo "<span class='$action'>$link$sep</span>"; |
397 } |
435 } |
|
436 |
398 echo '</small></span><br/>'; |
437 echo '</small></span><br/>'; |
399 } |
438 } |
400 } |
439 } |
401 |
440 |
402 /** |
441 /** |
403 * Handles the default column output. |
442 * Handles the default column output. |
404 * |
443 * |
405 * @since 4.3.0 |
444 * @since 4.3.0 |
406 * |
445 * |
407 * @param WP_User $user The current WP_User object. |
446 * @param WP_User $user The current WP_User object. |
408 * @param string $column_name The current column name. |
447 * @param string $column_name The current column name. |
409 */ |
448 */ |
410 public function column_default( $user, $column_name ) { |
449 public function column_default( $user, $column_name ) { |
411 /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ |
450 /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ |
412 echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); |
451 echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); |
413 } |
452 } |
452 * @since 4.3.0 |
491 * @since 4.3.0 |
453 * |
492 * |
454 * @param object $user User being acted upon. |
493 * @param object $user User being acted upon. |
455 * @param string $column_name Current column name. |
494 * @param string $column_name Current column name. |
456 * @param string $primary Primary column name. |
495 * @param string $primary Primary column name. |
457 * @return string Row actions output for users in Multisite. |
496 * @return string Row actions output for users in Multisite, or an empty string |
|
497 * if the current column is not the primary column. |
458 */ |
498 */ |
459 protected function handle_row_actions( $user, $column_name, $primary ) { |
499 protected function handle_row_actions( $user, $column_name, $primary ) { |
460 if ( $primary !== $column_name ) { |
500 if ( $primary !== $column_name ) { |
461 return ''; |
501 return ''; |
462 } |
502 } |
468 if ( current_user_can( 'edit_user', $user->ID ) ) { |
508 if ( current_user_can( 'edit_user', $user->ID ) ) { |
469 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); |
509 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); |
470 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
510 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
471 } |
511 } |
472 |
512 |
473 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { |
513 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins, true ) ) { |
474 $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; |
514 $actions['delete'] = '<a href="' . esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; |
475 } |
515 } |
476 |
516 |
477 /** |
517 /** |
478 * Filters the action links displayed under each user in the Network Admin Users list table. |
518 * Filters the action links displayed under each user in the Network Admin Users list table. |
479 * |
519 * |
481 * |
521 * |
482 * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'Delete'. |
522 * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'Delete'. |
483 * @param WP_User $user WP_User object. |
523 * @param WP_User $user WP_User object. |
484 */ |
524 */ |
485 $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); |
525 $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); |
|
526 |
486 return $this->row_actions( $actions ); |
527 return $this->row_actions( $actions ); |
487 } |
528 } |
488 } |
529 } |