Make WordPress Core

Ticket #37684: 37684.3.diff

File 37684.3.diff, 3.4 KB (added by pbiron, 6 years ago)

pass the current site to the 'display_site_states' filter.

  • src/wp-admin/includes/class-wp-ms-sites-list-table.php

    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 { 
    311311                global $mode;
    312312
    313313                $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 .= ' &mdash; ';
    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                 }
    333314
    334315                ?>
    335316                <strong>
    336317                        <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 ); ?>
    338319                </strong>
    339320                <?php
     321
    340322                if ( 'list' !== $mode ) {
    341323                        switch_to_blog( $blog['blog_id'] );
    342324                        echo '<p>';
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    344326                                /* translators: 1: site name, 2: site tagline. */
    345327                                __( '%1$s &#8211; %2$s' ),
    346328                                get_option( 'blogname' ),
    347                                 '<em>' . get_option( 'blogdescription ' ) . '</em>'
     329                                '<em>' . get_option( 'blogdescription' ) . '</em>'
    348330                        );
    349331                        echo '</p>';
    350332                        restore_current_blog();
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    491473                }
    492474        }
    493475
     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 ' &mdash; ';
     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
    494524        /**
    495525         * Gets the name of the default primary column.
    496526         *