Make WordPress Core

Ticket #37392: 37392.7.patch

File 37392.7.patch, 4.9 KB (added by mnelson4, 6 years ago)

Same as previous but I missed one line had spaces instead of tabs (IDE refuses to comply!)

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

    From 28b952eeca1423173a36a2aa10f64151a1a50cf2 Mon Sep 17 00:00:00 2001
    From: mike nelson <michael@eventespresso.com>
    Date: Fri, 6 Jul 2018 19:09:26 +0000
    Subject: [PATCH] add links to filter sites in sites list table
    
    ---
     .../includes/class-wp-ms-sites-list-table.php      | 49 ++++++++++++++++++++++
     src/wp-admin/network/sites.php                     |  2 +
     src/wp-includes/ms-blogs.php                       | 47 +++++++++++++++++++++
     3 files changed, 98 insertions(+)
    
    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 0cfef5b27c..71822e5029 100644
    a b 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 { 
    198203                _e( 'No sites found.' );
    199204        }
    200205
     206        /**
     207         * Gets links to filter sites by status.
     208         *
     209         * @since 5.0.0
     210         *
     211         * @return array
     212         */
     213        protected function get_views() {
     214                $counts = wp_count_sites();
     215
     216                $statuses = array(
     217                        'all'      => _n_noop( 'All <span class="count">(%s)</span>', 'All <span class="count">(%1$s)</span>' ),
     218                        'public'   => _n_noop( 'Public <span class="count">(%s)</span>' ,'Public <span class="count">(%1$s)</span>' ),
     219                        'archived' => _n_noop( 'Archived <span class="count">(%1$s)</span>', 'Archived <span class="count">(%1$s)</span>' ),
     220                        'mature'   => _n_noop( 'Mature <span class="count">(%1$s)</span>', 'Mature <span class="count">(%1$s)</span>' ),
     221                        'spam'     => _n_noop( 'Spam <span class="count">(%1$s)</span>', 'Spam <span class="count">(%1$s)</span>' ),
     222                        'deleted'  => _n_noop( 'Deleted <span class="count">(%1$s)</span>', 'Deleted <span class="count">(%1$s)</span>' ),
     223                );
     224
     225                $view_links       = array();
     226                $requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
     227                $url              = 'sites.php';
     228
     229                foreach ( $statuses as $status => $label_count ) {
     230                        $current_link_attributes = $requested_status === $status || ( $requested_status === '' && 'all' === $status )
     231                                ? ' class="current" aria-current="page"'
     232                                : '';
     233                        if ( (int) $counts->{$status} > 0 ) {
     234                                $label = sprintf( translate_nooped_plural( $label_count, $counts->{$status} ), number_format_i18n( $counts->{$status} ) );
     235
     236                                $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url );
     237
     238                                $view_links[ $status ] = sprintf(
     239                                        '<a href="%1$s"%2$s>%3$s</a>',
     240                                        esc_url( $full_url ),
     241                                        $current_link_attributes,
     242                                        $label
     243                                );
     244                        }
     245                }
     246
     247                return $view_links;
     248        }
     249
    201250        /**
    202251         * @return array
    203252         */
  • src/wp-admin/network/sites.php

    diff --git a/src/wp-admin/network/sites.php b/src/wp-admin/network/sites.php
    index 6c2de15866..8f81cf67b5 100644
    a b 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" class="wp-clearfix">
  • src/wp-includes/ms-blogs.php

    diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php
    index 9282833ac4..52823ba015 100644
    a b 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 *
     1546 * @global wpdb $wpdb WordPress database abstraction object.
     1547 *
     1548 * @param int $network_id Defaults to the current network id
     1549 *
     1550 * @return object Includes a grand total 'all' and an array of counts indexed by status strings: public, archived,
     1551 *                mature, spam, deleted
     1552 */
     1553function wp_count_sites( $network_id = null ) {
     1554        global $wpdb;
     1555
     1556        if ( ! $network_id ) {
     1557                $network_id = get_current_network_id();
     1558        }
     1559
     1560        $cache_key = 'counts-' . $network_id;
     1561
     1562        $counts = wp_cache_get( $cache_key, 'sites' );
     1563
     1564        if ( false !== $counts ) {
     1565                return $counts;
     1566        }
     1567
     1568        $counts = $wpdb->get_row(
     1569                $wpdb->prepare( '
     1570                        SELECT
     1571                        COUNT(blog_id) AS `all`,
     1572                        COUNT(IF(public=1,blog_id,NULL)) AS public,
     1573                        COUNT(IF(archived=1, blog_id, NULL)) AS archived,
     1574                        COUNT(IF(mature=1, blog_id, NULL)) AS mature,
     1575                        COUNT(IF(spam=1, blog_id, NULL)) AS spam,
     1576                        COUNT(IF(deleted=1, blog_id, NULL)) AS deleted
     1577                        FROM wp_blogs
     1578                        WHERE site_id=%d',
     1579                        $network_id
     1580                )
     1581        );
     1582
     1583        wp_cache_set( $cache_key, $counts, 'sites' );
     1584
     1585        return $counts;
     1586}