From 3ed86c8fd6f71eda8dc462190259122a60f13692 Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Wed, 5 Jun 2019 08:43:26 -0600
Subject: [PATCH] Allow sites to have filterable "states" akin to posts &
media.
---
.../includes/class-wp-ms-sites-list-table.php | 72 +++++++++++++------
1 file changed, 51 insertions(+), 21 deletions(-)
diff --git a/src/wp-admin/includes/class-wp-ms-sites-list-table.php b/src/wp-admin/includes/class-wp-ms-sites-list-table.php
index c9399b220b..6e58f90d80 100644
a
|
b
|
class WP_MS_Sites_List_Table extends WP_List_Table { |
311 | 311 | global $mode; |
312 | 312 | |
313 | 313 | $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 | 314 | |
334 | 315 | ?> |
335 | 316 | <strong> |
336 | 317 | <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; ?> |
| 318 | <?php $this->site_states( $blog ); ?> |
338 | 319 | </strong> |
339 | 320 | <?php |
| 321 | |
340 | 322 | if ( 'list' !== $mode ) { |
341 | 323 | switch_to_blog( $blog['blog_id'] ); |
342 | 324 | echo '<p>'; |
… |
… |
class WP_MS_Sites_List_Table extends WP_List_Table { |
344 | 326 | /* translators: 1: site name, 2: site tagline. */ |
345 | 327 | __( '%1$s – %2$s' ), |
346 | 328 | get_option( 'blogname' ), |
347 | | '<em>' . get_option( 'blogdescription ' ) . '</em>' |
| 329 | '<em>' . get_option( 'blogdescription' ) . '</em>' |
348 | 330 | ); |
349 | 331 | echo '</p>'; |
350 | 332 | restore_current_blog(); |
… |
… |
class WP_MS_Sites_List_Table extends WP_List_Table { |
491 | 473 | } |
492 | 474 | } |
493 | 475 | |
| 476 | /** |
| 477 | * Maybe output comma-separated site states. |
| 478 | * |
| 479 | * @since 5.3.0 |
| 480 | * |
| 481 | * @param array $site |
| 482 | */ |
| 483 | protected function site_states( $site ) { |
| 484 | $site_states = array(); |
| 485 | |
| 486 | // $site is still an array, so get the object. |
| 487 | $_site = WP_Site::get_instance( $site['blog_id'] ); |
| 488 | |
| 489 | if ( is_main_site( $_site->id ) ) { |
| 490 | $site_states['main'] = __( 'Main' ); |
| 491 | } |
| 492 | |
| 493 | reset( $this->status_list ); |
| 494 | |
| 495 | foreach ( $this->status_list as $status => $col ) { |
| 496 | if ( $_site->{$status} == 1 ) { |
| 497 | $site_states[] = $col[1]; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Filter the default site display states for items in the Sites list table. |
| 503 | * |
| 504 | * @since 5.3.0 |
| 505 | * |
| 506 | * @param array $site_states An array of site states. Default 'Main', |
| 507 | * 'Archived', 'Mature', 'Spam', 'Deleted'. |
| 508 | * @param WP_Site $site The current site object. |
| 509 | */ |
| 510 | $site_states = apply_filters( 'display_site_states', $site_states, $_site ); |
| 511 | |
| 512 | if ( ! empty( $site_states ) ) { |
| 513 | $state_count = count( $site_states ); |
| 514 | $i = 0; |
| 515 | echo ' — '; |
| 516 | foreach ( $site_states as $state ) { |
| 517 | ++$i; |
| 518 | ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
| 519 | echo "<span class='post-state'>{$state}{$sep}</span>"; |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
494 | 524 | /** |
495 | 525 | * Gets the name of the default primary column. |
496 | 526 | * |