60 /** |
60 /** |
61 * Prepares the list of sites for display. |
61 * Prepares the list of sites for display. |
62 * |
62 * |
63 * @since 3.1.0 |
63 * @since 3.1.0 |
64 * |
64 * |
|
65 * @global string $mode List table view mode. |
65 * @global string $s |
66 * @global string $s |
66 * @global string $mode |
67 * @global wpdb $wpdb WordPress database abstraction object. |
67 * @global wpdb $wpdb |
|
68 */ |
68 */ |
69 public function prepare_items() { |
69 public function prepare_items() { |
70 global $s, $mode, $wpdb; |
70 global $mode, $s, $wpdb; |
71 |
71 |
72 if ( ! empty( $_REQUEST['mode'] ) ) { |
72 if ( ! empty( $_REQUEST['mode'] ) ) { |
73 $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; |
73 $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list'; |
74 set_user_setting( 'sites_list_mode', $mode ); |
74 set_user_setting( 'sites_list_mode', $mode ); |
75 } else { |
75 } else { |
76 $mode = get_user_setting( 'sites_list_mode', 'list' ); |
76 $mode = get_user_setting( 'sites_list_mode', 'list' ); |
77 } |
77 } |
78 |
78 |
91 * If the network is large and a search is not being performed, show only |
91 * If the network is large and a search is not being performed, show only |
92 * the latest sites with no paging in order to avoid expensive count queries. |
92 * the latest sites with no paging in order to avoid expensive count queries. |
93 */ |
93 */ |
94 if ( ! $s && wp_is_large_network() ) { |
94 if ( ! $s && wp_is_large_network() ) { |
95 if ( ! isset( $_REQUEST['orderby'] ) ) { |
95 if ( ! isset( $_REQUEST['orderby'] ) ) { |
96 $_GET['orderby'] = $_REQUEST['orderby'] = ''; |
96 $_GET['orderby'] = ''; |
|
97 $_REQUEST['orderby'] = ''; |
97 } |
98 } |
98 if ( ! isset( $_REQUEST['order'] ) ) { |
99 if ( ! isset( $_REQUEST['order'] ) ) { |
99 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
100 $_GET['order'] = 'DESC'; |
|
101 $_REQUEST['order'] = 'DESC'; |
100 } |
102 } |
101 } |
103 } |
102 |
104 |
103 $args = array( |
105 $args = array( |
104 'number' => intval( $per_page ), |
106 'number' => intval( $per_page ), |
110 // Nothing to do. |
112 // Nothing to do. |
111 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || |
113 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || |
112 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
114 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
113 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
115 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
114 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { |
116 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { |
115 // IPv4 address |
117 // IPv4 address. |
116 $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) ); |
118 $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) ); |
117 $reg_blog_ids = $wpdb->get_col( $sql ); |
119 $reg_blog_ids = $wpdb->get_col( $sql ); |
118 |
120 |
119 if ( $reg_blog_ids ) { |
121 if ( $reg_blog_ids ) { |
120 $args['site__in'] = $reg_blog_ids; |
122 $args['site__in'] = $reg_blog_ids; |
198 public function no_items() { |
206 public function no_items() { |
199 _e( 'No sites found.' ); |
207 _e( 'No sites found.' ); |
200 } |
208 } |
201 |
209 |
202 /** |
210 /** |
|
211 * Gets links to filter sites by status. |
|
212 * |
|
213 * @since 5.3.0 |
|
214 * |
|
215 * @return array |
|
216 */ |
|
217 protected function get_views() { |
|
218 $counts = wp_count_sites(); |
|
219 |
|
220 $statuses = array( |
|
221 /* translators: %s: Number of sites. */ |
|
222 'all' => _nx_noop( |
|
223 'All <span class="count">(%s)</span>', |
|
224 'All <span class="count">(%s)</span>', |
|
225 'sites' |
|
226 ), |
|
227 |
|
228 /* translators: %s: Number of sites. */ |
|
229 'public' => _n_noop( |
|
230 'Public <span class="count">(%s)</span>', |
|
231 'Public <span class="count">(%s)</span>' |
|
232 ), |
|
233 |
|
234 /* translators: %s: Number of sites. */ |
|
235 'archived' => _n_noop( |
|
236 'Archived <span class="count">(%s)</span>', |
|
237 'Archived <span class="count">(%s)</span>' |
|
238 ), |
|
239 |
|
240 /* translators: %s: Number of sites. */ |
|
241 'mature' => _n_noop( |
|
242 'Mature <span class="count">(%s)</span>', |
|
243 'Mature <span class="count">(%s)</span>' |
|
244 ), |
|
245 |
|
246 /* translators: %s: Number of sites. */ |
|
247 'spam' => _nx_noop( |
|
248 'Spam <span class="count">(%s)</span>', |
|
249 'Spam <span class="count">(%s)</span>', |
|
250 'sites' |
|
251 ), |
|
252 |
|
253 /* translators: %s: Number of sites. */ |
|
254 'deleted' => _n_noop( |
|
255 'Deleted <span class="count">(%s)</span>', |
|
256 'Deleted <span class="count">(%s)</span>' |
|
257 ), |
|
258 ); |
|
259 |
|
260 $view_links = array(); |
|
261 $requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : ''; |
|
262 $url = 'sites.php'; |
|
263 |
|
264 foreach ( $statuses as $status => $label_count ) { |
|
265 $current_link_attributes = $requested_status === $status || ( '' === $requested_status && 'all' === $status ) |
|
266 ? ' class="current" aria-current="page"' |
|
267 : ''; |
|
268 if ( (int) $counts[ $status ] > 0 ) { |
|
269 $label = sprintf( translate_nooped_plural( $label_count, $counts[ $status ] ), number_format_i18n( $counts[ $status ] ) ); |
|
270 $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url ); |
|
271 |
|
272 $view_links[ $status ] = sprintf( |
|
273 '<a href="%1$s"%2$s>%3$s</a>', |
|
274 esc_url( $full_url ), |
|
275 $current_link_attributes, |
|
276 $label |
|
277 ); |
|
278 } |
|
279 } |
|
280 |
|
281 return $view_links; |
|
282 } |
|
283 |
|
284 /** |
203 * @return array |
285 * @return array |
204 */ |
286 */ |
205 protected function get_bulk_actions() { |
287 protected function get_bulk_actions() { |
206 $actions = array(); |
288 $actions = array(); |
207 if ( current_user_can( 'delete_sites' ) ) { |
289 if ( current_user_can( 'delete_sites' ) ) { |
208 $actions['delete'] = __( 'Delete' ); |
290 $actions['delete'] = __( 'Delete' ); |
209 } |
291 } |
210 $actions['spam'] = _x( 'Mark as Spam', 'site' ); |
292 $actions['spam'] = _x( 'Mark as spam', 'site' ); |
211 $actions['notspam'] = _x( 'Not Spam', 'site' ); |
293 $actions['notspam'] = _x( 'Not spam', 'site' ); |
212 |
294 |
213 return $actions; |
295 return $actions; |
214 } |
296 } |
215 |
297 |
216 /** |
298 /** |
217 * @global string $mode List table view mode. |
299 * @global string $mode List table view mode. |
218 * |
300 * |
219 * @param string $which |
301 * @param string $which The location of the pagination nav markup: 'top' or 'bottom'. |
220 */ |
302 */ |
221 protected function pagination( $which ) { |
303 protected function pagination( $which ) { |
222 global $mode; |
304 global $mode; |
223 |
305 |
224 parent::pagination( $which ); |
306 parent::pagination( $which ); |
225 |
307 |
226 if ( 'top' === $which ) { |
308 if ( 'top' === $which ) { |
227 $this->view_switcher( $mode ); |
309 $this->view_switcher( $mode ); |
228 } |
310 } |
|
311 } |
|
312 |
|
313 /** |
|
314 * Extra controls to be displayed between bulk actions and pagination. |
|
315 * |
|
316 * @since 5.3.0 |
|
317 * |
|
318 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. |
|
319 */ |
|
320 protected function extra_tablenav( $which ) { |
|
321 ?> |
|
322 <div class="alignleft actions"> |
|
323 <?php |
|
324 if ( 'top' === $which ) { |
|
325 ob_start(); |
|
326 |
|
327 /** |
|
328 * Fires before the Filter button on the MS sites list table. |
|
329 * |
|
330 * @since 5.3.0 |
|
331 * |
|
332 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. |
|
333 */ |
|
334 do_action( 'restrict_manage_sites', $which ); |
|
335 $output = ob_get_clean(); |
|
336 if ( ! empty( $output ) ) { |
|
337 echo $output; |
|
338 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'site-query-submit' ) ); |
|
339 } |
|
340 } |
|
341 ?> |
|
342 </div> |
|
343 <?php |
|
344 /** |
|
345 * Fires immediately following the closing "actions" div in the tablenav for the |
|
346 * MS sites list table. |
|
347 * |
|
348 * @since 5.3.0 |
|
349 * |
|
350 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. |
|
351 */ |
|
352 do_action( 'manage_sites_extra_tablenav', $which ); |
229 } |
353 } |
230 |
354 |
231 /** |
355 /** |
232 * @return array |
356 * @return array |
233 */ |
357 */ |
308 * @param array $blog Current site. |
433 * @param array $blog Current site. |
309 */ |
434 */ |
310 public function column_blogname( $blog ) { |
435 public function column_blogname( $blog ) { |
311 global $mode; |
436 global $mode; |
312 |
437 |
313 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
438 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
314 $blog_states = array(); |
|
315 reset( $this->status_list ); |
|
316 |
|
317 foreach ( $this->status_list as $status => $col ) { |
|
318 if ( $blog[ $status ] == 1 ) { |
|
319 $blog_states[] = $col[1]; |
|
320 } |
|
321 } |
|
322 $blog_state = ''; |
|
323 if ( ! empty( $blog_states ) ) { |
|
324 $state_count = count( $blog_states ); |
|
325 $i = 0; |
|
326 $blog_state .= ' — '; |
|
327 foreach ( $blog_states as $state ) { |
|
328 ++$i; |
|
329 $sep = ( $i == $state_count ) ? '' : ', '; |
|
330 $blog_state .= "<span class='post-state'>$state$sep</span>"; |
|
331 } |
|
332 } |
|
333 |
439 |
334 ?> |
440 ?> |
335 <strong> |
441 <strong> |
336 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname; ?></a> |
442 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname; ?></a> |
337 <?php echo $blog_state; ?> |
443 <?php $this->site_states( $blog ); ?> |
338 </strong> |
444 </strong> |
339 <?php |
445 <?php |
340 if ( 'list' !== $mode ) { |
446 if ( 'list' !== $mode ) { |
341 switch_to_blog( $blog['blog_id'] ); |
447 switch_to_blog( $blog['blog_id'] ); |
342 echo '<p>'; |
448 echo '<p>'; |
343 printf( |
449 printf( |
344 /* translators: 1: site name, 2: site tagline. */ |
450 /* translators: 1: Site title, 2: Site tagline. */ |
345 __( '%1$s – %2$s' ), |
451 __( '%1$s – %2$s' ), |
346 get_option( 'blogname' ), |
452 get_option( 'blogname' ), |
347 '<em>' . get_option( 'blogdescription ' ) . '</em>' |
453 '<em>' . get_option( 'blogdescription' ) . '</em>' |
348 ); |
454 ); |
349 echo '</p>'; |
455 echo '</p>'; |
350 restore_current_blog(); |
456 restore_current_blog(); |
351 } |
457 } |
352 } |
458 } |
467 */ |
573 */ |
468 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); |
574 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); |
469 } |
575 } |
470 |
576 |
471 /** |
577 /** |
472 * @global string $mode |
578 * @global string $mode List table view mode. |
473 */ |
579 */ |
474 public function display_rows() { |
580 public function display_rows() { |
475 foreach ( $this->items as $blog ) { |
581 foreach ( $this->items as $blog ) { |
476 $blog = $blog->to_array(); |
582 $blog = $blog->to_array(); |
477 $class = ''; |
583 $class = ''; |
478 reset( $this->status_list ); |
584 reset( $this->status_list ); |
479 |
585 |
480 foreach ( $this->status_list as $status => $col ) { |
586 foreach ( $this->status_list as $status => $col ) { |
481 if ( $blog[ $status ] == 1 ) { |
587 if ( 1 == $blog[ $status ] ) { |
482 $class = " class='{$col[0]}'"; |
588 $class = " class='{$col[0]}'"; |
483 } |
589 } |
484 } |
590 } |
485 |
591 |
486 echo "<tr{$class}>"; |
592 echo "<tr{$class}>"; |
487 |
593 |
488 $this->single_row_columns( $blog ); |
594 $this->single_row_columns( $blog ); |
489 |
595 |
490 echo '</tr>'; |
596 echo '</tr>'; |
|
597 } |
|
598 } |
|
599 |
|
600 /** |
|
601 * Maybe output comma-separated site states. |
|
602 * |
|
603 * @since 5.3.0 |
|
604 * |
|
605 * @param array $site |
|
606 */ |
|
607 protected function site_states( $site ) { |
|
608 $site_states = array(); |
|
609 |
|
610 // $site is still an array, so get the object. |
|
611 $_site = WP_Site::get_instance( $site['blog_id'] ); |
|
612 |
|
613 if ( is_main_site( $_site->id ) ) { |
|
614 $site_states['main'] = __( 'Main' ); |
|
615 } |
|
616 |
|
617 reset( $this->status_list ); |
|
618 |
|
619 $site_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : ''; |
|
620 foreach ( $this->status_list as $status => $col ) { |
|
621 if ( ( 1 === intval( $_site->{$status} ) ) && ( $site_status !== $status ) ) { |
|
622 $site_states[ $col[0] ] = $col[1]; |
|
623 } |
|
624 } |
|
625 |
|
626 /** |
|
627 * Filter the default site display states for items in the Sites list table. |
|
628 * |
|
629 * @since 5.3.0 |
|
630 * |
|
631 * @param array $site_states An array of site states. Default 'Main', |
|
632 * 'Archived', 'Mature', 'Spam', 'Deleted'. |
|
633 * @param WP_Site $site The current site object. |
|
634 */ |
|
635 $site_states = apply_filters( 'display_site_states', $site_states, $_site ); |
|
636 |
|
637 if ( ! empty( $site_states ) ) { |
|
638 $state_count = count( $site_states ); |
|
639 $i = 0; |
|
640 echo ' — '; |
|
641 foreach ( $site_states as $state ) { |
|
642 ++$i; |
|
643 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
|
644 echo "<span class='post-state'>{$state}{$sep}</span>"; |
|
645 } |
491 } |
646 } |
492 } |
647 } |
493 |
648 |
494 /** |
649 /** |
495 * Gets the name of the default primary column. |
650 * Gets the name of the default primary column. |
508 * @since 4.3.0 |
663 * @since 4.3.0 |
509 * |
664 * |
510 * @param object $blog Site being acted upon. |
665 * @param object $blog Site being acted upon. |
511 * @param string $column_name Current column name. |
666 * @param string $column_name Current column name. |
512 * @param string $primary Primary column name. |
667 * @param string $primary Primary column name. |
513 * @return string Row actions output. |
668 * @return string Row actions output for sites in Multisite, or an empty string |
|
669 * if the current column is not the primary column. |
514 */ |
670 */ |
515 protected function handle_row_actions( $blog, $column_name, $primary ) { |
671 protected function handle_row_actions( $blog, $column_name, $primary ) { |
516 if ( $primary !== $column_name ) { |
672 if ( $primary !== $column_name ) { |
517 return; |
673 return ''; |
518 } |
674 } |
519 |
675 |
520 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
676 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
521 |
677 |
522 // Preordered. |
678 // Preordered. |
534 ); |
690 ); |
535 |
691 |
536 $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>'; |
692 $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>'; |
537 $actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>'; |
693 $actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>'; |
538 if ( get_network()->site_id != $blog['blog_id'] ) { |
694 if ( get_network()->site_id != $blog['blog_id'] ) { |
539 if ( $blog['deleted'] == '1' ) { |
695 if ( '1' == $blog['deleted'] ) { |
540 $actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>'; |
696 $actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>'; |
541 } else { |
697 } else { |
542 $actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a>'; |
698 $actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a>'; |
543 } |
699 } |
544 |
700 |
545 if ( $blog['archived'] == '1' ) { |
701 if ( '1' == $blog['archived'] ) { |
546 $actions['unarchive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unarchiveblog&id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a>'; |
702 $actions['unarchive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unarchiveblog&id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a>'; |
547 } else { |
703 } else { |
548 $actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=archiveblog&id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>'; |
704 $actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=archiveblog&id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>'; |
549 } |
705 } |
550 |
706 |
551 if ( $blog['spam'] == '1' ) { |
707 if ( '1' == $blog['spam'] ) { |
552 $actions['unspam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unspamblog&id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a>'; |
708 $actions['unspam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unspamblog&id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a>'; |
553 } else { |
709 } else { |
554 $actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=spamblog&id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>'; |
710 $actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=spamblog&id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>'; |
555 } |
711 } |
556 |
712 |