15 * |
15 * |
16 * @see WP_List_Table |
16 * @see WP_List_Table |
17 */ |
17 */ |
18 class WP_MS_Users_List_Table extends WP_List_Table { |
18 class WP_MS_Users_List_Table extends WP_List_Table { |
19 /** |
19 /** |
20 * |
|
21 * @return bool |
20 * @return bool |
22 */ |
21 */ |
23 public function ajax_user_can() { |
22 public function ajax_user_can() { |
24 return current_user_can( 'manage_network_users' ); |
23 return current_user_can( 'manage_network_users' ); |
25 } |
24 } |
26 |
25 |
27 /** |
26 /** |
28 * |
|
29 * @global string $usersearch |
27 * @global string $usersearch |
30 * @global string $role |
28 * @global string $role |
31 * @global wpdb $wpdb |
|
32 * @global string $mode |
29 * @global string $mode |
33 */ |
30 */ |
34 public function prepare_items() { |
31 public function prepare_items() { |
35 global $usersearch, $role, $wpdb, $mode; |
32 global $usersearch, $role, $mode; |
36 |
33 |
37 $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; |
34 $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; |
38 |
35 |
39 $users_per_page = $this->get_items_per_page( 'users_network_per_page' ); |
36 $users_per_page = $this->get_items_per_page( 'users_network_per_page' ); |
40 |
37 |
41 $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : ''; |
38 $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : ''; |
42 |
39 |
43 $paged = $this->get_pagenum(); |
40 $paged = $this->get_pagenum(); |
44 |
41 |
45 $args = array( |
42 $args = array( |
46 'number' => $users_per_page, |
43 'number' => $users_per_page, |
47 'offset' => ( $paged-1 ) * $users_per_page, |
44 'offset' => ( $paged - 1 ) * $users_per_page, |
48 'search' => $usersearch, |
45 'search' => $usersearch, |
49 'blog_id' => 0, |
46 'blog_id' => 0, |
50 'fields' => 'all_with_meta' |
47 'fields' => 'all_with_meta', |
51 ); |
48 ); |
52 |
49 |
53 if ( wp_is_large_network( 'users' ) ) { |
50 if ( wp_is_large_network( 'users' ) ) { |
54 $args['search'] = ltrim( $args['search'], '*' ); |
51 $args['search'] = ltrim( $args['search'], '*' ); |
55 } else if ( '' !== $args['search'] ) { |
52 } elseif ( '' !== $args['search'] ) { |
56 $args['search'] = trim( $args['search'], '*' ); |
53 $args['search'] = trim( $args['search'], '*' ); |
57 $args['search'] = '*' . $args['search'] . '*'; |
54 $args['search'] = '*' . $args['search'] . '*'; |
58 } |
55 } |
59 |
56 |
60 if ( $role === 'super' ) { |
57 if ( $role === 'super' ) { |
61 $logins = implode( "', '", get_super_admins() ); |
58 $args['login__in'] = get_super_admins(); |
62 $args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" ); |
|
63 } |
59 } |
64 |
60 |
65 /* |
61 /* |
66 * If the network is large and a search is not being performed, |
62 * If the network is large and a search is not being performed, |
67 * show only the latest users with no paging in order to avoid |
63 * show only the latest users with no paging in order to avoid |
68 * expensive count queries. |
64 * expensive count queries. |
69 */ |
65 */ |
70 if ( !$usersearch && wp_is_large_network( 'users' ) ) { |
66 if ( ! $usersearch && wp_is_large_network( 'users' ) ) { |
71 if ( !isset($_REQUEST['orderby']) ) |
67 if ( ! isset( $_REQUEST['orderby'] ) ) { |
72 $_GET['orderby'] = $_REQUEST['orderby'] = 'id'; |
68 $_GET['orderby'] = $_REQUEST['orderby'] = 'id'; |
73 if ( !isset($_REQUEST['order']) ) |
69 } |
|
70 if ( ! isset( $_REQUEST['order'] ) ) { |
74 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
71 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
|
72 } |
75 $args['count_total'] = false; |
73 $args['count_total'] = false; |
76 } |
74 } |
77 |
75 |
78 if ( isset( $_REQUEST['orderby'] ) ) |
76 if ( isset( $_REQUEST['orderby'] ) ) { |
79 $args['orderby'] = $_REQUEST['orderby']; |
77 $args['orderby'] = $_REQUEST['orderby']; |
80 |
78 } |
81 if ( isset( $_REQUEST['order'] ) ) |
79 |
|
80 if ( isset( $_REQUEST['order'] ) ) { |
82 $args['order'] = $_REQUEST['order']; |
81 $args['order'] = $_REQUEST['order']; |
|
82 } |
83 |
83 |
84 if ( ! empty( $_REQUEST['mode'] ) ) { |
84 if ( ! empty( $_REQUEST['mode'] ) ) { |
85 $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; |
85 $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; |
86 set_user_setting( 'network_users_list_mode', $mode ); |
86 set_user_setting( 'network_users_list_mode', $mode ); |
87 } else { |
87 } else { |
94 // Query the user IDs for this page |
94 // Query the user IDs for this page |
95 $wp_user_search = new WP_User_Query( $args ); |
95 $wp_user_search = new WP_User_Query( $args ); |
96 |
96 |
97 $this->items = $wp_user_search->get_results(); |
97 $this->items = $wp_user_search->get_results(); |
98 |
98 |
99 $this->set_pagination_args( array( |
99 $this->set_pagination_args( |
100 'total_items' => $wp_user_search->get_total(), |
100 array( |
101 'per_page' => $users_per_page, |
101 'total_items' => $wp_user_search->get_total(), |
102 ) ); |
102 'per_page' => $users_per_page, |
103 } |
103 ) |
104 |
104 ); |
105 /** |
105 } |
106 * |
106 |
|
107 /** |
107 * @return array |
108 * @return array |
108 */ |
109 */ |
109 protected function get_bulk_actions() { |
110 protected function get_bulk_actions() { |
110 $actions = array(); |
111 $actions = array(); |
111 if ( current_user_can( 'delete_users' ) ) |
112 if ( current_user_can( 'delete_users' ) ) { |
112 $actions['delete'] = __( 'Delete' ); |
113 $actions['delete'] = __( 'Delete' ); |
113 $actions['spam'] = _x( 'Mark as Spam', 'user' ); |
114 } |
|
115 $actions['spam'] = _x( 'Mark as Spam', 'user' ); |
114 $actions['notspam'] = _x( 'Not Spam', 'user' ); |
116 $actions['notspam'] = _x( 'Not Spam', 'user' ); |
115 |
117 |
116 return $actions; |
118 return $actions; |
117 } |
119 } |
118 |
120 |
121 public function no_items() { |
123 public function no_items() { |
122 _e( 'No users found.' ); |
124 _e( 'No users found.' ); |
123 } |
125 } |
124 |
126 |
125 /** |
127 /** |
126 * |
|
127 * @global string $role |
128 * @global string $role |
128 * @return array |
129 * @return array |
129 */ |
130 */ |
130 protected function get_views() { |
131 protected function get_views() { |
131 global $role; |
132 global $role; |
132 |
133 |
133 $total_users = get_user_count(); |
134 $total_users = get_user_count(); |
134 $super_admins = get_super_admins(); |
135 $super_admins = get_super_admins(); |
135 $total_admins = count( $super_admins ); |
136 $total_admins = count( $super_admins ); |
136 |
137 |
137 $current_link_attributes = $role !== 'super' ? ' class="current" aria-current="page"' : ''; |
138 $current_link_attributes = $role !== 'super' ? ' class="current" aria-current="page"' : ''; |
138 $role_links = array(); |
139 $role_links = array(); |
139 $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>'; |
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>'; |
140 $current_link_attributes = $role === 'super' ? ' class="current" aria-current="page"' : ''; |
141 $current_link_attributes = $role === 'super' ? ' class="current" aria-current="page"' : ''; |
141 $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>'; |
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>'; |
142 |
143 |
143 return $role_links; |
144 return $role_links; |
144 } |
145 } |
145 |
146 |
146 /** |
147 /** |
149 * @param string $which |
150 * @param string $which |
150 */ |
151 */ |
151 protected function pagination( $which ) { |
152 protected function pagination( $which ) { |
152 global $mode; |
153 global $mode; |
153 |
154 |
154 parent::pagination ( $which ); |
155 parent::pagination( $which ); |
155 |
156 |
156 if ( 'top' === $which ) { |
157 if ( 'top' === $which ) { |
157 $this->view_switcher( $mode ); |
158 $this->view_switcher( $mode ); |
158 } |
159 } |
159 } |
160 } |
160 |
161 |
161 /** |
162 /** |
162 * |
|
163 * @return array |
163 * @return array |
164 */ |
164 */ |
165 public function get_columns() { |
165 public function get_columns() { |
166 $users_columns = array( |
166 $users_columns = array( |
167 'cb' => '<input type="checkbox" />', |
167 'cb' => '<input type="checkbox" />', |
168 'username' => __( 'Username' ), |
168 'username' => __( 'Username' ), |
169 'name' => __( 'Name' ), |
169 'name' => __( 'Name' ), |
170 'email' => __( 'Email' ), |
170 'email' => __( 'Email' ), |
171 'registered' => _x( 'Registered', 'user' ), |
171 'registered' => _x( 'Registered', 'user' ), |
172 'blogs' => __( 'Sites' ) |
172 'blogs' => __( 'Sites' ), |
173 ); |
173 ); |
174 /** |
174 /** |
175 * Filters the columns displayed in the Network Admin Users list table. |
175 * Filters the columns displayed in the Network Admin Users list table. |
176 * |
176 * |
177 * @since MU (3.0.0) |
177 * @since MU (3.0.0) |
178 * |
178 * |
179 * @param array $users_columns An array of user columns. Default 'cb', 'username', |
179 * @param string[] $users_columns An array of user columns. Default 'cb', 'username', |
180 * 'name', 'email', 'registered', 'blogs'. |
180 * 'name', 'email', 'registered', 'blogs'. |
181 */ |
181 */ |
182 return apply_filters( 'wpmu_users_columns', $users_columns ); |
182 return apply_filters( 'wpmu_users_columns', $users_columns ); |
183 } |
183 } |
184 |
184 |
185 /** |
185 /** |
186 * |
|
187 * @return array |
186 * @return array |
188 */ |
187 */ |
189 protected function get_sortable_columns() { |
188 protected function get_sortable_columns() { |
190 return array( |
189 return array( |
191 'username' => 'login', |
190 'username' => 'login', |
230 * |
229 * |
231 * @param WP_User $user The current WP_User object. |
230 * @param WP_User $user The current WP_User object. |
232 */ |
231 */ |
233 public function column_username( $user ) { |
232 public function column_username( $user ) { |
234 $super_admins = get_super_admins(); |
233 $super_admins = get_super_admins(); |
235 $avatar = get_avatar( $user->user_email, 32 ); |
234 $avatar = get_avatar( $user->user_email, 32 ); |
236 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); |
|
237 |
235 |
238 echo $avatar; |
236 echo $avatar; |
239 |
237 |
240 ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php |
238 if ( current_user_can( 'edit_user', $user->ID ) ) { |
241 if ( in_array( $user->user_login, $super_admins ) ) { |
239 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); |
242 echo ' — ' . __( 'Super Admin' ); |
240 $edit = "<a href=\"{$edit_link}\">{$user->user_login}</a>"; |
243 } |
241 } else { |
244 ?></strong> |
242 $edit = $user->user_login; |
245 <?php |
243 } |
|
244 |
|
245 ?> |
|
246 <strong> |
|
247 <?php |
|
248 echo $edit; |
|
249 |
|
250 if ( in_array( $user->user_login, $super_admins ) ) { |
|
251 echo ' — ' . __( 'Super Admin' ); |
|
252 } |
|
253 ?> |
|
254 </strong> |
|
255 <?php |
246 } |
256 } |
247 |
257 |
248 /** |
258 /** |
249 * Handles the name column output. |
259 * Handles the name column output. |
250 * |
260 * |
325 foreach ( $blogs as $val ) { |
335 foreach ( $blogs as $val ) { |
326 if ( ! can_edit_network( $val->site_id ) ) { |
336 if ( ! can_edit_network( $val->site_id ) ) { |
327 continue; |
337 continue; |
328 } |
338 } |
329 |
339 |
330 $path = ( $val->path === '/' ) ? '' : $val->path; |
340 $path = ( $val->path === '/' ) ? '' : $val->path; |
331 echo '<span class="site-' . $val->site_id . '" >'; |
341 $site_classes = array( 'site-' . $val->site_id ); |
332 echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_network()->domain, '', $val->domain . $path ) . '</a>'; |
342 /** |
|
343 * Filters the span class for a site listing on the mulisite user list table. |
|
344 * |
|
345 * @since 5.2.0 |
|
346 * |
|
347 * @param array $site_classes Class used within the span tag. Default "site-#" with the site's network ID. |
|
348 * @param int $site_id Site ID. |
|
349 * @param int $network_id Network ID. |
|
350 * @param object $user WP_User object. |
|
351 */ |
|
352 $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 ) ) { |
|
354 $site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) ); |
|
355 echo '<span class="' . esc_attr( implode( ' ', $site_classes ) ) . '">'; |
|
356 } else { |
|
357 echo '<span>'; |
|
358 } |
|
359 echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) . '">' . str_replace( '.' . get_network()->domain, '', $val->domain . $path ) . '</a>'; |
333 echo ' <small class="row-actions">'; |
360 echo ' <small class="row-actions">'; |
334 $actions = array(); |
361 $actions = array(); |
335 $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>'; |
362 $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>'; |
336 |
363 |
337 $class = ''; |
364 $class = ''; |
338 if ( $val->spam == 1 ) { |
365 if ( $val->spam == 1 ) { |
339 $class .= 'site-spammed '; |
366 $class .= 'site-spammed '; |
340 } |
367 } |
354 * Filters the action links displayed next the sites a user belongs to |
381 * Filters the action links displayed next the sites a user belongs to |
355 * in the Network Admin Users list table. |
382 * in the Network Admin Users list table. |
356 * |
383 * |
357 * @since 3.1.0 |
384 * @since 3.1.0 |
358 * |
385 * |
359 * @param array $actions An array of action links to be displayed. |
386 * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'View'. |
360 * Default 'Edit', 'View'. |
387 * @param int $userblog_id The site ID. |
361 * @param int $userblog_id The site ID. |
|
362 */ |
388 */ |
363 $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); |
389 $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); |
364 |
390 |
365 $i=0; |
391 $i = 0; |
366 $action_count = count( $actions ); |
392 $action_count = count( $actions ); |
367 foreach ( $actions as $action => $link ) { |
393 foreach ( $actions as $action => $link ) { |
368 ++$i; |
394 ++$i; |
369 $sep = ( $i == $action_count ) ? '' : ' | '; |
395 $sep = ( $i == $action_count ) ? '' : ' | '; |
370 echo "<span class='$action'>$link$sep</span>"; |
396 echo "<span class='$action'>$link$sep</span>"; |
431 if ( $primary !== $column_name ) { |
460 if ( $primary !== $column_name ) { |
432 return ''; |
461 return ''; |
433 } |
462 } |
434 |
463 |
435 $super_admins = get_super_admins(); |
464 $super_admins = get_super_admins(); |
436 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); |
|
437 |
465 |
438 $actions = array(); |
466 $actions = array(); |
439 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
467 |
|
468 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 ) ) ); |
|
470 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
|
471 } |
440 |
472 |
441 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { |
473 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { |
442 $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>'; |
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>'; |
443 } |
475 } |
444 |
476 |
445 /** |
477 /** |
446 * Filters the action links displayed under each user in the Network Admin Users list table. |
478 * Filters the action links displayed under each user in the Network Admin Users list table. |
447 * |
479 * |
448 * @since 3.2.0 |
480 * @since 3.2.0 |
449 * |
481 * |
450 * @param array $actions An array of action links to be displayed. |
482 * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'Delete'. |
451 * Default 'Edit', 'Delete'. |
483 * @param WP_User $user WP_User object. |
452 * @param WP_User $user WP_User object. |
|
453 */ |
484 */ |
454 $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); |
485 $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); |
455 return $this->row_actions( $actions ); |
486 return $this->row_actions( $actions ); |
456 } |
487 } |
457 } |
488 } |