70 'total_items' => $wp_user_search->get_total(), |
100 'total_items' => $wp_user_search->get_total(), |
71 'per_page' => $users_per_page, |
101 'per_page' => $users_per_page, |
72 ) ); |
102 ) ); |
73 } |
103 } |
74 |
104 |
|
105 /** |
|
106 * |
|
107 * @return array |
|
108 */ |
75 protected function get_bulk_actions() { |
109 protected function get_bulk_actions() { |
76 $actions = array(); |
110 $actions = array(); |
77 if ( current_user_can( 'delete_users' ) ) |
111 if ( current_user_can( 'delete_users' ) ) |
78 $actions['delete'] = __( 'Delete' ); |
112 $actions['delete'] = __( 'Delete' ); |
79 $actions['spam'] = _x( 'Mark as Spam', 'user' ); |
113 $actions['spam'] = _x( 'Mark as Spam', 'user' ); |
80 $actions['notspam'] = _x( 'Not Spam', 'user' ); |
114 $actions['notspam'] = _x( 'Not Spam', 'user' ); |
81 |
115 |
82 return $actions; |
116 return $actions; |
83 } |
117 } |
84 |
118 |
|
119 /** |
|
120 */ |
85 public function no_items() { |
121 public function no_items() { |
86 _e( 'No users found.' ); |
122 _e( 'No users found.' ); |
87 } |
123 } |
88 |
124 |
|
125 /** |
|
126 * |
|
127 * @global string $role |
|
128 * @return array |
|
129 */ |
89 protected function get_views() { |
130 protected function get_views() { |
90 global $role; |
131 global $role; |
91 |
132 |
92 $total_users = get_user_count(); |
133 $total_users = get_user_count(); |
93 $super_admins = get_super_admins(); |
134 $super_admins = get_super_admins(); |
94 $total_admins = count( $super_admins ); |
135 $total_admins = count( $super_admins ); |
95 |
136 |
96 $class = $role != 'super' ? ' class="current"' : ''; |
137 $current_link_attributes = $role !== 'super' ? ' class="current" aria-current="page"' : ''; |
97 $role_links = array(); |
138 $role_links = array(); |
98 $role_links['all'] = "<a href='" . network_admin_url('users.php') . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; |
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>'; |
99 $class = $role == 'super' ? ' class="current"' : ''; |
140 $current_link_attributes = $role === 'super' ? ' class="current" aria-current="page"' : ''; |
100 $role_links['super'] = "<a href='" . network_admin_url('users.php?role=super') . "'$class>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>'; |
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>'; |
101 |
142 |
102 return $role_links; |
143 return $role_links; |
103 } |
144 } |
104 |
145 |
105 /** |
146 /** |
106 * @global string $mode |
147 * @global string $mode List table view mode. |
|
148 * |
107 * @param string $which |
149 * @param string $which |
108 */ |
150 */ |
109 protected function pagination( $which ) { |
151 protected function pagination( $which ) { |
110 global $mode; |
152 global $mode; |
111 |
153 |
112 parent::pagination ( $which ); |
154 parent::pagination ( $which ); |
113 |
155 |
114 if ( 'top' == $which ) |
156 if ( 'top' === $which ) { |
115 $this->view_switcher( $mode ); |
157 $this->view_switcher( $mode ); |
116 } |
158 } |
117 |
159 } |
|
160 |
|
161 /** |
|
162 * |
|
163 * @return array |
|
164 */ |
118 public function get_columns() { |
165 public function get_columns() { |
119 $users_columns = array( |
166 $users_columns = array( |
120 'cb' => '<input type="checkbox" />', |
167 'cb' => '<input type="checkbox" />', |
121 'username' => __( 'Username' ), |
168 'username' => __( 'Username' ), |
122 'name' => __( 'Name' ), |
169 'name' => __( 'Name' ), |
123 'email' => __( 'E-mail' ), |
170 'email' => __( 'Email' ), |
124 'registered' => _x( 'Registered', 'user' ), |
171 'registered' => _x( 'Registered', 'user' ), |
125 'blogs' => __( 'Sites' ) |
172 'blogs' => __( 'Sites' ) |
126 ); |
173 ); |
127 /** |
174 /** |
128 * Filter the columns displayed in the Network Admin Users list table. |
175 * Filters the columns displayed in the Network Admin Users list table. |
129 * |
176 * |
130 * @since MU |
177 * @since MU (3.0.0) |
131 * |
178 * |
132 * @param array $users_columns An array of user columns. Default 'cb', 'username', |
179 * @param array $users_columns An array of user columns. Default 'cb', 'username', |
133 * 'name', 'email', 'registered', 'blogs'. |
180 * 'name', 'email', 'registered', 'blogs'. |
134 */ |
181 */ |
135 $users_columns = apply_filters( 'wpmu_users_columns', $users_columns ); |
182 return apply_filters( 'wpmu_users_columns', $users_columns ); |
136 |
183 } |
137 return $users_columns; |
184 |
138 } |
185 /** |
139 |
186 * |
|
187 * @return array |
|
188 */ |
140 protected function get_sortable_columns() { |
189 protected function get_sortable_columns() { |
141 return array( |
190 return array( |
142 'username' => 'login', |
191 'username' => 'login', |
143 'name' => 'name', |
192 'name' => 'name', |
144 'email' => 'email', |
193 'email' => 'email', |
145 'registered' => 'id', |
194 'registered' => 'id', |
146 ); |
195 ); |
147 } |
196 } |
148 |
197 |
|
198 /** |
|
199 * Handles the checkbox column output. |
|
200 * |
|
201 * @since 4.3.0 |
|
202 * |
|
203 * @param WP_User $user The current WP_User object. |
|
204 */ |
|
205 public function column_cb( $user ) { |
|
206 if ( is_super_admin( $user->ID ) ) { |
|
207 return; |
|
208 } |
|
209 ?> |
|
210 <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label> |
|
211 <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" /> |
|
212 <?php |
|
213 } |
|
214 |
|
215 /** |
|
216 * Handles the ID column output. |
|
217 * |
|
218 * @since 4.4.0 |
|
219 * |
|
220 * @param WP_User $user The current WP_User object. |
|
221 */ |
|
222 public function column_id( $user ) { |
|
223 echo $user->ID; |
|
224 } |
|
225 |
|
226 /** |
|
227 * Handles the username column output. |
|
228 * |
|
229 * @since 4.3.0 |
|
230 * |
|
231 * @param WP_User $user The current WP_User object. |
|
232 */ |
|
233 public function column_username( $user ) { |
|
234 $super_admins = get_super_admins(); |
|
235 $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 |
|
238 echo $avatar; |
|
239 |
|
240 ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php |
|
241 if ( in_array( $user->user_login, $super_admins ) ) { |
|
242 echo ' — ' . __( 'Super Admin' ); |
|
243 } |
|
244 ?></strong> |
|
245 <?php |
|
246 } |
|
247 |
|
248 /** |
|
249 * Handles the name column output. |
|
250 * |
|
251 * @since 4.3.0 |
|
252 * |
|
253 * @param WP_User $user The current WP_User object. |
|
254 */ |
|
255 public function column_name( $user ) { |
|
256 if ( $user->first_name && $user->last_name ) { |
|
257 echo "$user->first_name $user->last_name"; |
|
258 } elseif ( $user->first_name ) { |
|
259 echo $user->first_name; |
|
260 } elseif ( $user->last_name ) { |
|
261 echo $user->last_name; |
|
262 } else { |
|
263 echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . _x( 'Unknown', 'name' ) . '</span>'; |
|
264 } |
|
265 } |
|
266 |
|
267 /** |
|
268 * Handles the email column output. |
|
269 * |
|
270 * @since 4.3.0 |
|
271 * |
|
272 * @param WP_User $user The current WP_User object. |
|
273 */ |
|
274 public function column_email( $user ) { |
|
275 echo "<a href='" . esc_url( "mailto:$user->user_email" ) . "'>$user->user_email</a>"; |
|
276 } |
|
277 |
|
278 /** |
|
279 * Handles the registered date column output. |
|
280 * |
|
281 * @since 4.3.0 |
|
282 * |
|
283 * @global string $mode List table view mode. |
|
284 * |
|
285 * @param WP_User $user The current WP_User object. |
|
286 */ |
|
287 public function column_registered( $user ) { |
|
288 global $mode; |
|
289 if ( 'list' === $mode ) { |
|
290 $date = __( 'Y/m/d' ); |
|
291 } else { |
|
292 $date = __( 'Y/m/d g:i:s a' ); |
|
293 } |
|
294 echo mysql2date( $date, $user->user_registered ); |
|
295 } |
|
296 |
|
297 /** |
|
298 * @since 4.3.0 |
|
299 * |
|
300 * @param WP_User $user |
|
301 * @param string $classes |
|
302 * @param string $data |
|
303 * @param string $primary |
|
304 */ |
|
305 protected function _column_blogs( $user, $classes, $data, $primary ) { |
|
306 echo '<td class="', $classes, ' has-row-actions" ', $data, '>'; |
|
307 echo $this->column_blogs( $user ); |
|
308 echo $this->handle_row_actions( $user, 'blogs', $primary ); |
|
309 echo '</td>'; |
|
310 } |
|
311 |
|
312 /** |
|
313 * Handles the sites column output. |
|
314 * |
|
315 * @since 4.3.0 |
|
316 * |
|
317 * @param WP_User $user The current WP_User object. |
|
318 */ |
|
319 public function column_blogs( $user ) { |
|
320 $blogs = get_blogs_of_user( $user->ID, true ); |
|
321 if ( ! is_array( $blogs ) ) { |
|
322 return; |
|
323 } |
|
324 |
|
325 foreach ( $blogs as $val ) { |
|
326 if ( ! can_edit_network( $val->site_id ) ) { |
|
327 continue; |
|
328 } |
|
329 |
|
330 $path = ( $val->path === '/' ) ? '' : $val->path; |
|
331 echo '<span class="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>'; |
|
333 echo ' <small class="row-actions">'; |
|
334 $actions = array(); |
|
335 $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>'; |
|
336 |
|
337 $class = ''; |
|
338 if ( $val->spam == 1 ) { |
|
339 $class .= 'site-spammed '; |
|
340 } |
|
341 if ( $val->mature == 1 ) { |
|
342 $class .= 'site-mature '; |
|
343 } |
|
344 if ( $val->deleted == 1 ) { |
|
345 $class .= 'site-deleted '; |
|
346 } |
|
347 if ( $val->archived == 1 ) { |
|
348 $class .= 'site-archived '; |
|
349 } |
|
350 |
|
351 $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>'; |
|
352 |
|
353 /** |
|
354 * Filters the action links displayed next the sites a user belongs to |
|
355 * in the Network Admin Users list table. |
|
356 * |
|
357 * @since 3.1.0 |
|
358 * |
|
359 * @param array $actions An array of action links to be displayed. |
|
360 * Default 'Edit', 'View'. |
|
361 * @param int $userblog_id The site ID. |
|
362 */ |
|
363 $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); |
|
364 |
|
365 $i=0; |
|
366 $action_count = count( $actions ); |
|
367 foreach ( $actions as $action => $link ) { |
|
368 ++$i; |
|
369 $sep = ( $i == $action_count ) ? '' : ' | '; |
|
370 echo "<span class='$action'>$link$sep</span>"; |
|
371 } |
|
372 echo '</small></span><br/>'; |
|
373 } |
|
374 } |
|
375 |
|
376 /** |
|
377 * Handles the default column output. |
|
378 * |
|
379 * @since 4.3.0 |
|
380 * |
|
381 * @param WP_User $user The current WP_User object. |
|
382 * @param string $column_name The current column name. |
|
383 */ |
|
384 public function column_default( $user, $column_name ) { |
|
385 /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ |
|
386 echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); |
|
387 } |
|
388 |
149 public function display_rows() { |
389 public function display_rows() { |
150 global $mode; |
|
151 |
|
152 $super_admins = get_super_admins(); |
|
153 foreach ( $this->items as $user ) { |
390 foreach ( $this->items as $user ) { |
154 $class = ''; |
391 $class = ''; |
155 |
392 |
156 $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); |
393 $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); |
157 |
394 |
158 foreach ( $status_list as $status => $col ) { |
395 foreach ( $status_list as $status => $col ) { |
159 if ( $user->$status ) |
396 if ( $user->$status ) { |
160 $class .= " $col"; |
397 $class .= " $col"; |
|
398 } |
161 } |
399 } |
162 |
400 |
163 ?> |
401 ?> |
164 <tr class="<?php echo trim( $class ); ?>"> |
402 <tr class="<?php echo trim( $class ); ?>"> |
165 <?php |
403 <?php $this->single_row_columns( $user ); ?> |
166 |
|
167 list( $columns, $hidden ) = $this->get_column_info(); |
|
168 |
|
169 foreach ( $columns as $column_name => $column_display_name ) : |
|
170 $class = "class='$column_name column-$column_name'"; |
|
171 |
|
172 $style = ''; |
|
173 if ( in_array( $column_name, $hidden ) ) |
|
174 $style = ' style="display:none;"'; |
|
175 |
|
176 $attributes = "$class$style"; |
|
177 |
|
178 switch ( $column_name ) { |
|
179 case 'cb': ?> |
|
180 <th scope="row" class="check-column"> |
|
181 <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label> |
|
182 <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" /> |
|
183 </th> |
|
184 <?php |
|
185 break; |
|
186 |
|
187 case 'username': |
|
188 $avatar = get_avatar( $user->user_email, 32 ); |
|
189 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); |
|
190 |
|
191 echo "<td $attributes>"; ?> |
|
192 <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php |
|
193 if ( in_array( $user->user_login, $super_admins ) ) |
|
194 echo ' - ' . __( 'Super Admin' ); |
|
195 ?></strong> |
|
196 <br/> |
|
197 <?php |
|
198 $actions = array(); |
|
199 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
|
200 |
|
201 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { |
|
202 $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>'; |
|
203 } |
|
204 |
|
205 /** |
|
206 * Filter the action links displayed under each user |
|
207 * in the Network Admin Users list table. |
|
208 * |
|
209 * @since 3.2.0 |
|
210 * |
|
211 * @param array $actions An array of action links to be displayed. |
|
212 * Default 'Edit', 'Delete'. |
|
213 * @param WP_User $user WP_User object. |
|
214 */ |
|
215 $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); |
|
216 echo $this->row_actions( $actions ); |
|
217 ?> |
|
218 </td> |
|
219 <?php |
|
220 break; |
|
221 |
|
222 case 'name': |
|
223 echo "<td $attributes>$user->first_name $user->last_name</td>"; |
|
224 break; |
|
225 |
|
226 case 'email': |
|
227 echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>"; |
|
228 break; |
|
229 |
|
230 case 'registered': |
|
231 if ( 'list' == $mode ) |
|
232 $date = __( 'Y/m/d' ); |
|
233 else |
|
234 $date = __( 'Y/m/d g:i:s a' ); |
|
235 |
|
236 echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>"; |
|
237 break; |
|
238 |
|
239 case 'blogs': |
|
240 $blogs = get_blogs_of_user( $user->ID, true ); |
|
241 echo "<td $attributes>"; |
|
242 if ( is_array( $blogs ) ) { |
|
243 foreach ( (array) $blogs as $key => $val ) { |
|
244 if ( !can_edit_network( $val->site_id ) ) |
|
245 continue; |
|
246 |
|
247 $path = ( $val->path == '/' ) ? '' : $val->path; |
|
248 echo '<span class="site-' . $val->site_id . '" >'; |
|
249 echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>'; |
|
250 echo ' <small class="row-actions">'; |
|
251 $actions = array(); |
|
252 $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>'; |
|
253 |
|
254 $class = ''; |
|
255 if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 ) |
|
256 $class .= 'site-spammed '; |
|
257 if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 ) |
|
258 $class .= 'site-mature '; |
|
259 if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 ) |
|
260 $class .= 'site-deleted '; |
|
261 if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 ) |
|
262 $class .= 'site-archived '; |
|
263 |
|
264 $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>'; |
|
265 |
|
266 /** |
|
267 * Filter the action links displayed next the sites a user belongs to |
|
268 * in the Network Admin Users list table. |
|
269 * |
|
270 * @since 3.1.0 |
|
271 * |
|
272 * @param array $actions An array of action links to be displayed. |
|
273 * Default 'Edit', 'View'. |
|
274 * @param int $userblog_id The site ID. |
|
275 */ |
|
276 $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); |
|
277 |
|
278 $i=0; |
|
279 $action_count = count( $actions ); |
|
280 foreach ( $actions as $action => $link ) { |
|
281 ++$i; |
|
282 ( $i == $action_count ) ? $sep = '' : $sep = ' | '; |
|
283 echo "<span class='$action'>$link$sep</span>"; |
|
284 } |
|
285 echo '</small></span><br/>'; |
|
286 } |
|
287 } |
|
288 ?> |
|
289 </td> |
|
290 <?php |
|
291 break; |
|
292 |
|
293 default: |
|
294 echo "<td $attributes>"; |
|
295 /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ |
|
296 echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); |
|
297 echo "</td>"; |
|
298 break; |
|
299 } |
|
300 endforeach |
|
301 ?> |
|
302 </tr> |
404 </tr> |
303 <?php |
405 <?php |
304 } |
406 } |
305 } |
407 } |
|
408 |
|
409 /** |
|
410 * Gets the name of the default primary column. |
|
411 * |
|
412 * @since 4.3.0 |
|
413 * |
|
414 * @return string Name of the default primary column, in this case, 'username'. |
|
415 */ |
|
416 protected function get_default_primary_column_name() { |
|
417 return 'username'; |
|
418 } |
|
419 |
|
420 /** |
|
421 * Generates and displays row action links. |
|
422 * |
|
423 * @since 4.3.0 |
|
424 * |
|
425 * @param object $user User being acted upon. |
|
426 * @param string $column_name Current column name. |
|
427 * @param string $primary Primary column name. |
|
428 * @return string Row actions output for users in Multisite. |
|
429 */ |
|
430 protected function handle_row_actions( $user, $column_name, $primary ) { |
|
431 if ( $primary !== $column_name ) { |
|
432 return ''; |
|
433 } |
|
434 |
|
435 $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 |
|
438 $actions = array(); |
|
439 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
|
440 |
|
441 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>'; |
|
443 } |
|
444 |
|
445 /** |
|
446 * Filters the action links displayed under each user in the Network Admin Users list table. |
|
447 * |
|
448 * @since 3.2.0 |
|
449 * |
|
450 * @param array $actions An array of action links to be displayed. |
|
451 * Default 'Edit', 'Delete'. |
|
452 * @param WP_User $user WP_User object. |
|
453 */ |
|
454 $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); |
|
455 return $this->row_actions( $actions ); |
|
456 } |
306 } |
457 } |