Make WordPress Core

Ticket #37684: 37684.03.diff

File 37684.03.diff, 2.9 KB (added by johnjamesjacoby, 8 years ago)

An alternative approach that adds site_states() as a method in WP_MS_Sites_List_Table. This is cleaner, but makes the idea & output exclusive to this list table object, meaning plugins wanting to take advantage of site-states would need to duplicate this bit of code.

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

    diff --git src/wp-admin/includes/class-wp-ms-sites-list-table.php src/wp-admin/includes/class-wp-ms-sites-list-table.php
    index 9ce3ffe..a130df2 100644
     
    303303                global $mode;
    304304
    305305                $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
    306                 $blog_states = array();
    307                 reset( $this->status_list );
    308 
    309                 foreach ( $this->status_list as $status => $col ) {
    310                         if ( $blog[ $status ] == 1 ) {
    311                                 $blog_states[] = $col[1];
    312                         }
    313                 }
    314                 $blog_state = '';
    315                 if ( ! empty( $blog_states ) ) {
    316                         $state_count = count( $blog_states );
    317                         $i = 0;
    318                         $blog_state .= ' - ';
    319                         foreach ( $blog_states as $state ) {
    320                                 ++$i;
    321                                 $sep = ( $i == $state_count ) ? '' : ', ';
    322                                 $blog_state .= "<span class='post-state'>$state$sep</span>";
    323                         }
    324                 }
    325 
    326306                ?>
    327                 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
     307                <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname; ?></a>
    328308                <?php
     309
     310                $this->site_states( $blog );
     311
    329312                if ( 'list' !== $mode ) {
    330313                        switch_to_blog( $blog['blog_id'] );
    331314                        echo '<p>';
     
    333316                                /* translators: 1: site name, 2: site tagline. */
    334317                                __( '%1$s &#8211; %2$s' ),
    335318                                get_option( 'blogname' ),
    336                                 '<em>' . get_option( 'blogdescription ' ) . '</em>'
     319                                '<em>' . get_option( 'blogdescription' ) . '</em>'
    337320                        );
    338321                        echo '</p>';
    339322                        restore_current_blog();
     
    477460        }
    478461
    479462        /**
     463         * Maybe output comma-separated site states
     464         *
     465         * @since 4.7.0
     466         *
     467         * @param array $site
     468         */
     469        protected function site_states( $site ) {
     470                $site_states = array();
     471
     472                // $site is still an array, so get the object
     473                $_site = WP_Site::get_instance( $site['blog_id'] );
     474
     475                if ( is_main_site( $_site->id ) ) {
     476                        $site_states['deleted'] = __( 'Main' );
     477                }
     478
     479                reset( $this->status_list );
     480
     481                foreach ( $this->status_list as $status => $col ) {
     482                        if ( $_site->{$status} == 1 ) {
     483                                $site_states[] = $col[1];
     484                        }
     485                }
     486
     487                /**
     488                 * Filter the default site display states for items in the Sites list table.
     489                 *
     490                 * @since 4.7.0
     491                 *
     492                 * @param array $site_states An array of site states. Default 'Main',
     493                 *                            'Archived', 'Mature', 'Spam', 'Deleted'.
     494                 */
     495                $site_states = apply_filters( 'display_site_states', $site_states );
     496
     497                if ( ! empty( $site_states ) ) {
     498                        $state_count = count( $site_states );
     499                        $i = 0;
     500                        echo ' &mdash; ';
     501                        foreach ( $site_states as $state ) {
     502                                ++$i;
     503                                ( $i == $state_count ) ? $sep = '' : $sep = ', ';
     504                                echo "<span class='post-state'>{$state}{$sep}</span>";
     505                        }
     506                }
     507        }
     508
     509        /**
    480510         * Gets the name of the default primary column.
    481511         *
    482512         * @since 4.3.0