Make WordPress Core

Ticket #37392: 37392.5.patch

File 37392.5.patch, 4.4 KB (added by mnelson4, 7 years ago)

Patch uploaded in response to https://core.trac.wordpress.org/ticket/37392#comment:16

  • 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 5caa62c..f2efad9 100644
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    157157                } else {
    158158                        $args['no_found_rows'] = false;
    159159                }
     160                //take into account the role the user has selected
     161                $status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
     162                if ( in_array( $status, array( 'public', 'archived', 'mature', 'spam', 'deleted' ), true ) ) {
     163                        $args[ $status ] = 1;
     164                }
    160165
    161166                /**
    162167                 * Filters the arguments for the site query in the sites list table.
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    199204        }
    200205
    201206        /**
     207     * Gets links to filter sites by status
     208     * @since 5.0.0
     209         * @return array
     210         */
     211        protected function get_views() {
     212                $counts        = wp_count_sites();
     213                $statuses = array(
     214                        'all'      => _n_noop( 'All <span class="count">(%s)</span>', 'All <span class="count">(%1$s)</span>' ),
     215                        'public'   => _n_noop( 'Public <span class="count">(%s)</span>' ,'Public <span class="count">(%1$s)</span>' ),
     216                        'archived' => _n_noop( 'Archived <span class="count">(%1$s)</span>', 'Archived <span class="count">(%1$s)</span>' ),
     217                        'mature'   => _n_noop( 'Mature <span class="count">(%1$s)</span>', 'Mature <span class="count">(%1$s)</span>' ),
     218                        'spam'     => _n_noop( 'Spam <span class="count">(%1$s)</span>', 'Spam <span class="count">(%1$s)</span>' ),
     219                        'deleted'  => _n_noop( 'Deleted <span class="count">(%1$s)</span>', 'Deleted <span class="count">(%1$s)</span>' ),
     220                );
     221
     222                $view_links       = array();
     223                $requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
     224                $url              = 'sites.php';
     225
     226                foreach ( $statuses as $status => $label_count ) {
     227                        $current_link_attributes = $requested_status === $status || ( $requested_status === '' && 'all' === $status )
     228                                ? ' class="current" aria-current="page"'
     229                                : '';
     230                        if ( (int) $counts->{$status} > 0 ) {
     231                                $label = sprintf( translate_nooped_plural( $label_count, $counts->{$status} ), number_format_i18n( $counts->{$status} ) );
     232                                $full_url = 'all' == $status ? $url : add_query_arg( 'status', $status, $url );
     233                                $view_links[ $status ] = sprintf(
     234                                        '<a href="%1$s"%2$s>%3$s</a>',
     235                                        esc_url( $full_url ),
     236                                        $current_link_attributes,
     237                                        $label
     238                                );
     239                        }
     240                }
     241
     242                return $view_links;
     243        }
     244
     245        /**
    202246         * @return array
    203247         */
    204248        protected function get_bulk_actions() {
  • src/wp-admin/network/sites.php

    diff --git src/wp-admin/network/sites.php src/wp-admin/network/sites.php
    index b5b55bd..322282e 100644
    if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { 
    355355
    356356<hr class="wp-header-end">
    357357
     358<?php $wp_list_table->views(); ?>
     359
    358360<?php echo $msg; ?>
    359361
    360362<form method="get" id="ms-search">
  • src/wp-includes/ms-blogs.php

    diff --git src/wp-includes/ms-blogs.php src/wp-includes/ms-blogs.php
    index 9282833..8ba626e 100644
    function _update_posts_count_on_transition_post_status( $new_status, $old_status 
    15371537
    15381538        update_posts_count();
    15391539}
     1540
     1541/**
     1542 * Count number of sites grouped by site status.
     1543 *
     1544 * @since 5.0.0
     1545 * @global wpdb $wpdb       WordPress database abstraction object.
     1546 *
     1547 * @param int   $network_id Defaults to the current network id
     1548 *
     1549 * @return object Includes a grand total 'all' and an array of counts indexed by status strings: public, archived,
     1550 *                mature, spam, deleted
     1551 */
     1552function wp_count_sites( $network_id = null ) {
     1553        global $wpdb;
     1554        if ( ! $network_id ) {
     1555                $network_id = get_current_network_id();
     1556        }
     1557        $cache_key = 'counts-' . $network_id;
     1558        $counts    = wp_cache_get( $cache_key, 'sites' );
     1559        if ( false !== $counts ) {
     1560                return $counts;
     1561        }
     1562        $counts = $wpdb->get_row(
     1563                $wpdb->prepare( '
     1564                        SELECT
     1565                        COUNT(blog_id) AS `all`,
     1566                        COUNT(IF(public=1,blog_id,NULL)) AS public,
     1567                        COUNT(IF(archived=1, blog_id, NULL)) AS archived,
     1568                        COUNT(IF(mature=1, blog_id, NULL)) AS mature,
     1569                        COUNT(IF(spam=1, blog_id, NULL)) AS spam,
     1570                        COUNT(IF(deleted=1, blog_id, NULL)) AS deleted
     1571                        FROM wp_blogs
     1572                        WHERE site_id=%d',
     1573                        $network_id
     1574                )
     1575        );
     1576        wp_cache_set( $cache_key, $counts, 'sites' );
     1577
     1578        return $counts;
     1579}