WordPress.org

Make WordPress Core

Ticket #37392: 37392.2.diff

File 37392.2.diff, 4.8 KB (added by pbiron, 2 months ago)
  • src/wp-admin/includes/class-wp-ms-sites-list-table.php

    From 84490aa26469b4e11a789141c75aa5c3b14961c3 Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Wed, 18 Sep 2019 16:12:31 -0600
    Subject: [PATCH] Multisite "Sites" screen: Add links to filter websites by
     status.
    
    ---
     .../includes/class-wp-ms-sites-list-table.php | 50 +++++++++++++++++++
     src/wp-admin/network/sites.php                |  2 +
     src/wp-includes/ms-blogs.php                  | 39 +++++++++++++++
     3 files changed, 91 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 edcec3366d..1c0d723f80 100644
    a b class WP_MS_Sites_List_Table extends WP_List_Table { 
    160160                        $args['no_found_rows'] = false;
    161161                }
    162162
     163                // Take into account the role the user has selected.
     164                $status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
     165                if ( in_array( $status, array( 'public', 'archived', 'mature', 'spam', 'deleted' ), true ) ) {
     166                        $args[ $status ] = 1;
     167                }
     168
    163169                /**
    164170                 * Filters the arguments for the site query in the sites list table.
    165171                 *
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    201207                _e( 'No sites found.' );
    202208        }
    203209
     210        /**
     211         * Gets links to filter sites by status.
     212         *
     213         * @since 5.3.0
     214         *
     215         * @return array
     216         *
     217         */
     218        protected function get_views() {
     219                $counts = wp_count_sites();
     220
     221                $statuses = array(
     222                        'all'      => _n_noop( 'All <span class="count">(%s)</span>', 'All <span class="count">(%1$s)</span>' ),
     223                        'public'   => _n_noop( 'Public <span class="count">(%s)</span>', 'Public <span class="count">(%1$s)</span>' ),
     224                        'archived' => _n_noop( 'Archived <span class="count">(%1$s)</span>', 'Archived <span class="count">(%1$s)</span>' ),
     225                        'mature'   => _n_noop( 'Mature <span class="count">(%1$s)</span>', 'Mature <span class="count">(%1$s)</span>' ),
     226                        'spam'     => _n_noop( 'Spam <span class="count">(%1$s)</span>', 'Spam <span class="count">(%1$s)</span>' ),
     227                        'deleted'  => _n_noop( 'Deleted <span class="count">(%1$s)</span>', 'Deleted <span class="count">(%1$s)</span>' ),
     228                );
     229
     230                $view_links       = array();
     231                $requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
     232                $url              = 'sites.php';
     233
     234                foreach ( $statuses as $status => $label_count ) {
     235                        $current_link_attributes = $requested_status === $status || ( $requested_status === '' && 'all' === $status )
     236                                ? ' class="current" aria-current="page"'
     237                                : '';
     238                        if ( (int) $counts[ $status ] > 0 ) {
     239                                $label = sprintf( translate_nooped_plural( $label_count, $counts[ $status ] ), number_format_i18n( $counts[ $status ] ) );
     240                                $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url );
     241
     242                                $view_links[ $status ] = sprintf(
     243                                        '<a href="%1$s"%2$s>%3$s</a>',
     244                                        esc_url( $full_url ),
     245                                        $current_link_attributes,
     246                                        $label
     247                                );
     248                        }
     249                }
     250
     251                return $view_links;
     252        }
     253
    204254        /**
    205255         * @return array
    206256         */
  • src/wp-admin/network/sites.php

    diff --git a/src/wp-admin/network/sites.php b/src/wp-admin/network/sites.php
    index bfd5a1d4bd..848ad7f89e 100644
    a b if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { 
    371371
    372372<hr class="wp-header-end">
    373373
     374<?php $wp_list_table->views(); ?>
     375
    374376<?php echo $msg; ?>
    375377
    376378<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 02a55692dc..2874f7e1f0 100644
    a b function _update_posts_count_on_transition_post_status( $new_status, $old_status 
    853853
    854854        update_posts_count();
    855855}
     856
     857/**
     858 * Count number of sites grouped by site status.
     859 *
     860 * @since 5.3.0
     861 *
     862 * @param int $network_id The network to get counts for.  Default is the current network id.
     863 * @return array Includes a grand total 'all' and an array of counts indexed by
     864 *                status strings: public, archived, mature, spam, deleted.
     865 */
     866function wp_count_sites( $network_id = null ) {
     867        if ( empty( $network_id ) ) {
     868                $network_id = get_current_network_id();
     869        }
     870
     871        $counts = array();
     872        $args   = array(
     873                'network_id'    => $network_id,
     874                'number'        => 1,
     875                'fields'        => 'ids',
     876                'no_found_rows' => false,
     877        );
     878
     879        $q             = new WP_Site_Query( $args );
     880        $counts['all'] = $q->found_sites;
     881
     882        $_args    = $args;
     883        $statuses = array( 'public', 'archived', 'mature', 'spam', 'deleted' );
     884
     885        foreach ( $statuses as $status ) {
     886                $_args            = $args;
     887                $_args[ $status ] = 1;
     888
     889                $q                 = new WP_Site_Query( $_args );
     890                $counts[ $status ] = $q->found_sites;
     891        }
     892
     893        return $counts;
     894}