WordPress.org

Make WordPress Core

Changeset 46153


Ignore:
Timestamp:
09/16/2019 11:33:45 PM (2 months ago)
Author:
johnjamesjacoby
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-ms-sites-list-table.php

    r45932 r46153  
    314314        global $mode;
    315315
    316         $blogname    = untrailingslashit( $blog['domain'] . $blog['path'] );
    317         $blog_states = array();
    318         reset( $this->status_list );
    319 
    320         foreach ( $this->status_list as $status => $col ) {
    321             if ( $blog[ $status ] == 1 ) {
    322                 $blog_states[] = $col[1];
    323             }
    324         }
    325         $blog_state = '';
    326         if ( ! empty( $blog_states ) ) {
    327             $state_count = count( $blog_states );
    328             $i           = 0;
    329             $blog_state .= ' — ';
    330             foreach ( $blog_states as $state ) {
    331                 ++$i;
    332                 $sep         = ( $i == $state_count ) ? '' : ', ';
    333                 $blog_state .= "<span class='post-state'>$state$sep</span>";
    334             }
    335         }
     316        $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
    336317
    337318        ?>
    338319        <strong>
    339320            <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname; ?></a>
    340             <?php echo $blog_state; ?>
     321            <?php $this->site_states( $blog ); ?>
    341322        </strong>
    342323        <?php
     
    348329                __( '%1$s &#8211; %2$s' ),
    349330                get_option( 'blogname' ),
    350                 '<em>' . get_option( 'blogdescription ' ) . '</em>'
     331                '<em>' . get_option( 'blogdescription' ) . '</em>'
    351332            );
    352333            echo '</p>';
     
    496477
    497478    /**
     479     * Maybe output comma-separated site states.
     480     *
     481     * @since 5.3.0
     482     *
     483     * @param array $site
     484     */
     485    protected function site_states( $site ) {
     486        $site_states = array();
     487
     488        // $site is still an array, so get the object.
     489        $_site = WP_Site::get_instance( $site['blog_id'] );
     490
     491        if ( is_main_site( $_site->id ) ) {
     492            $site_states['main'] = __( 'Main' );
     493        }
     494
     495        reset( $this->status_list );
     496
     497        foreach ( $this->status_list as $status => $col ) {
     498            if ( $_site->{$status} == 1 ) {
     499                $site_states[ $col[0] ] = $col[1];
     500            }
     501        }
     502
     503        /**
     504         * Filter the default site display states for items in the Sites list table.
     505         *
     506         * @since 5.3.0
     507         *
     508         * @param array $site_states An array of site states. Default 'Main',
     509         *                           'Archived', 'Mature', 'Spam', 'Deleted'.
     510         * @param WP_Site $site The current site object.
     511         */
     512        $site_states = apply_filters( 'display_site_states', $site_states, $_site );
     513
     514        if ( ! empty( $site_states ) ) {
     515            $state_count = count( $site_states );
     516            $i           = 0;
     517            echo ' &mdash; ';
     518            foreach ( $site_states as $state ) {
     519                ++$i;
     520                ( $i == $state_count ) ? $sep = '' : $sep = ', ';
     521                echo "<span class='post-state'>{$state}{$sep}</span>";
     522            }
     523        }
     524    }
     525
     526    /**
    498527     * Gets the name of the default primary column.
    499528     *
Note: See TracChangeset for help on using the changeset viewer.