From 7cbb1f32a3b4a2c5b15fe4dd725ea739a429e736 Mon Sep 17 00:00:00 2001
From: John James Jacoby
Date: Mon, 16 Sep 2019 23:33:45 +0000
Subject: [PATCH] Network Admin: Allow Sites to have filterable States in List
Table rows.
This change introduces a new `site_states()` method to the Sites List Table class (with a new `display_site_states` filter inside of it) following the pattern popularized in other List Table classes before it (Posts, Media, etc...)
Fixes #37684. Props mnelson4, pbiron, jeremyfelt, johnjamesjacoby.
git-svn-id: https://develop.svn.wordpress.org/trunk@46153 602fd350-edb4-49c9-b593-d223f7449a82
---
.../includes/class-wp-ms-sites-list-table.php | 73 +++++++++++++------
1 file changed, 51 insertions(+), 22 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 220e834081..edcec3366d 100644
--- a/src/wp-admin/includes/class-wp-ms-sites-list-table.php
+++ b/src/wp-admin/includes/class-wp-ms-sites-list-table.php
@@ -313,31 +313,12 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
public function column_blogname( $blog ) {
global $mode;
- $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
- $blog_states = array();
- reset( $this->status_list );
-
- foreach ( $this->status_list as $status => $col ) {
- if ( $blog[ $status ] == 1 ) {
- $blog_states[] = $col[1];
- }
- }
- $blog_state = '';
- if ( ! empty( $blog_states ) ) {
- $state_count = count( $blog_states );
- $i = 0;
- $blog_state .= ' — ';
- foreach ( $blog_states as $state ) {
- ++$i;
- $sep = ( $i == $state_count ) ? '' : ', ';
- $blog_state .= "$state$sep";
- }
- }
+ $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
?>
-
+ site_states( $blog ); ?>
' . get_option( 'blogdescription ' ) . ''
+ '' . get_option( 'blogdescription' ) . ''
);
echo '
';
restore_current_blog();
@@ -494,6 +475,54 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
}
}
+ /**
+ * Maybe output comma-separated site states.
+ *
+ * @since 5.3.0
+ *
+ * @param array $site
+ */
+ protected function site_states( $site ) {
+ $site_states = array();
+
+ // $site is still an array, so get the object.
+ $_site = WP_Site::get_instance( $site['blog_id'] );
+
+ if ( is_main_site( $_site->id ) ) {
+ $site_states['main'] = __( 'Main' );
+ }
+
+ reset( $this->status_list );
+
+ foreach ( $this->status_list as $status => $col ) {
+ if ( $_site->{$status} == 1 ) {
+ $site_states[ $col[0] ] = $col[1];
+ }
+ }
+
+ /**
+ * Filter the default site display states for items in the Sites list table.
+ *
+ * @since 5.3.0
+ *
+ * @param array $site_states An array of site states. Default 'Main',
+ * 'Archived', 'Mature', 'Spam', 'Deleted'.
+ * @param WP_Site $site The current site object.
+ */
+ $site_states = apply_filters( 'display_site_states', $site_states, $_site );
+
+ if ( ! empty( $site_states ) ) {
+ $state_count = count( $site_states );
+ $i = 0;
+ echo ' — ';
+ foreach ( $site_states as $state ) {
+ ++$i;
+ ( $i == $state_count ) ? $sep = '' : $sep = ', ';
+ echo "{$state}{$sep}";
+ }
+ }
+ }
+
/**
* Gets the name of the default primary column.
*