From 757d077669494f7aaa552a0662b50f058c4ab71c Mon Sep 17 00:00:00 2001 From: johnjamesjacoby Date: Mon, 16 Sep 2019 23:34:55 +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. Built from https://develop.svn.wordpress.org/trunk@46153 git-svn-id: http://core.svn.wordpress.org/trunk@45965 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-ms-sites-list-table.php | 73 +++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/wp-admin/includes/class-wp-ms-sites-list-table.php b/wp-admin/includes/class-wp-ms-sites-list-table.php index 220e834081..edcec3366d 100644 --- a/wp-admin/includes/class-wp-ms-sites-list-table.php +++ b/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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index f31810bd76..99db90e656 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-46152'; +$wp_version = '5.3-alpha-46153'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.