Make WordPress Core

Ticket #38071: 38071.1.diff

File 38071.1.diff, 7.5 KB (added by pbiron, 6 years ago)

here's my patch, which is against the current core code

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

    From dfeadc373f6900d8787e109b94ffc15dba83e79a Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Thu, 4 May 2017 20:39:22 -0600
    Subject: [PATCH] trac ticket 38071
    
    ---
     wp-admin/includes/class-wp-ms-sites-list-table.php | 122 ++++++++++++++++++++-
     wp-admin/network/sites.php                         |   3 +
     wp-includes/ms-functions.php                       |  50 +++++++++
     3 files changed, 174 insertions(+), 1 deletion(-)
    
    diff --git a/wp-admin/includes/class-wp-ms-sites-list-table.php b/wp-admin/includes/class-wp-ms-sites-list-table.php
    index 4a43775..8993795 100644
    a b  
    1111 * Core class used to implement displaying sites in a list table for the network admin.
    1212 *
    1313 * @since 3.1.0
     14 * @since 4.8.x Added Site Status views, like on wp-admin/edit.php
    1415 * @access private
    1516 *
    1617 * @see WP_List_Table
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    2122         * Site status list.
    2223         *
    2324         * @since 4.3.0
     25         * @since 4.8.x Now used to display Site Status views, like on wp-admin/edit.php
    2426         * @access public
    2527         * @var array
    2628         */
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    3840         */
    3941        public function __construct( $args = array() ) {
    4042                $this->status_list = array(
     43                        'public' => array( 'site-public', __( 'Public' ) ),
    4144                        'archived' => array( 'site-archived', __( 'Archived' ) ),
    4245                        'spam'     => array( 'site-spammed', _x( 'Spam', 'site' ) ),
    4346                        'deleted'  => array( 'site-deleted', __( 'Deleted' ) ),
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    166169                 */
    167170                $args = apply_filters( 'ms_sites_list_table_query_args', $args );
    168171
     172                if ( isset( $_REQUEST['site_status'] ) && ! empty( $_REQUEST['site_status'] ) ) {
     173                        $args[$_REQUEST['site_status']] = 1;
     174                }
     175
    169176                $_sites = get_sites( $args );
    170177                if ( is_array( $_sites ) ) {
    171178                        update_site_cache( $_sites );
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    193200        }
    194201
    195202        /**
     203         * Determine if the current view is the "All" view.
     204         *
     205         * @since 4.8.x
     206         *
     207         * @return bool Whether the current view is the "All" view.
     208         */
     209        protected function is_base_request() {
     210                $vars = $_GET;
     211                unset( $vars['paged'] );
     212
     213                if ( empty( $vars ) ) {
     214                        return true;
     215                } elseif ( ! empty( $vars['site_status'] ) ) {
     216                        return false;
     217                }
     218
     219                return true;
     220        }
     221       
     222        /**
     223         * Helper to create links to sites.php with params.
     224         *
     225         * @since 4.8.x
     226         * @access protected
     227         *
     228         * @param array  $args  URL parameters for the link.
     229         * @param string $label Link text.
     230         * @param string $class Optional. Class attribute. Default empty string.
     231         * @return string The formatted link string.
     232         */
     233        protected function get_edit_link( $args, $label, $class = '' ) {
     234                $url = add_query_arg( $args, 'sites.php' );
     235
     236                $class_html = '';
     237                if ( ! empty( $class ) ) {
     238                         $class_html = sprintf(
     239                                ' class="%s"',
     240                                esc_attr( $class )
     241                        );
     242                }
     243
     244                return sprintf(
     245                        '<a href="%s"%s>%s</a>',
     246                        esc_url( $url ),
     247                        $class_html,
     248                        $label
     249                );
     250        }
     251
     252        /**
     253         * Get an associative array ( id => link ) with the list of views available on this table.
     254         *
     255         * @since 4.8.x
     256         * @return array
     257         */
     258        protected function get_views() {
     259                $num_sites = wp_count_sites();
     260                $total_sites = get_sites( array( 'count' => true, 'number' => 0 ) ) ;
     261
     262                $class = '';
     263                if ( $this->is_base_request() ) {
     264                        $class = 'current';
     265                }
     266
     267                $all_inner_html = sprintf(
     268                        _nx(
     269                                'All <span class="count">(%s)</span>',
     270                                'All <span class="count">(%s)</span>',
     271                                $total_sites,
     272                                'sites'
     273                        ),
     274                        number_format_i18n( $total_sites )
     275                );
     276
     277                $status_links = array() ;
     278
     279                $status_links['all'] = $this->get_edit_link( array (), $all_inner_html, $class );
     280
     281                foreach ( $this->status_list as $status => $status_name ) {
     282                        if ( ! $num_sites->{$status} ) {
     283                                continue;
     284                        }
     285
     286                        $class = '';
     287                        if ( isset( $_REQUEST['site_status'] ) && $status === $_REQUEST['site_status'] ) {
     288                                $class = 'current';
     289                        }
     290
     291                        $status_args = array(
     292                                'site_status' => $status,
     293                        );
     294
     295                        $status_name = $status_name[1];
     296                        $status_inner_html = sprintf(
     297                                _nx(
     298                                        $status_name . ' <span class="count">(%s)</span>',
     299                                        $status_name . ' <span class="count">(%s)</span>',
     300                                        $num_sites->{$status},
     301                                        'sites'
     302                                ),
     303                                number_format_i18n( $num_sites->{$status} )
     304                        );
     305
     306                        $status_links[$status] = $this->get_edit_link( $status_args, $status_inner_html, $class );
     307                        }
     308               
     309                return $status_links;
     310        }
     311
     312        /**
    196313         *
    197314         * @return array
    198315         */
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    307424                reset( $this->status_list );
    308425
    309426                foreach ( $this->status_list as $status => $col ) {
     427                        if ( isset( $_REQUEST['site_status'] ) && $status === $_REQUEST['site_status'] ) {
     428                                continue;
     429                        }
    310430                        if ( $blog[ $status ] == 1 ) {
    311431                                $blog_states[] = $col[1];
    312432                        }
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    319439                        foreach ( $blog_states as $state ) {
    320440                                ++$i;
    321441                                $sep = ( $i == $state_count ) ? '' : ', ';
    322                                 $blog_state .= "<span class='post-state'>$state$sep</span>";
     442                                $blog_state .= "<span class='site-state'>$state$sep</span>";
    323443                        }
    324444                }
    325445
  • wp-admin/network/sites.php

    diff --git a/wp-admin/network/sites.php b/wp-admin/network/sites.php
    index a0ec407..730c3ca 100644
    a b  
    55 * @package WordPress
    66 * @subpackage Multisite
    77 * @since 3.0.0
     8 * @since 4.8.x Added Site Status views, like on wp-admin/edit.php
    89 */
    910
    1011/** Load WordPress Administration Bootstrap */
    if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { 
    309310<input type="hidden" name="action" value="blogs" />
    310311</form>
    311312
     313<?php $wp_list_table->views(); ?>
     314
    312315<form id="form-site-list" action="sites.php?action=allblogs" method="post">
    313316        <?php $wp_list_table->display(); ?>
    314317</form>
  • wp-includes/ms-functions.php

    diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php
    index d209435..3356030 100644
    a b function get_subdirectory_reserved_names() { 
    25272527         */
    25282528        return apply_filters( 'subdirectory_reserved_names', $names );
    25292529}
     2530
     2531/**
     2532 * Count number of sites of a site status.
     2533 *
     2534 * This function provides an efficient method of finding the amount of sites
     2535 *
     2536 * @since 4.8.x
     2537 *
     2538 * @global wpdb $wpdb WordPress database abstraction object.
     2539 *
     2540 * @return object Number of sites for each status.
     2541 */
     2542function wp_count_sites( $network_id = null ) {
     2543        global $wpdb;
     2544
     2545        if ( is_null( $network_id ) ) {
     2546                // Get current network ID
     2547                $network_id = get_current_network_id();
     2548        }
     2549
     2550        // Bail if counts already cached
     2551        $counts = wp_cache_get( "sites-{$network_id}", 'networks' );
     2552        if ( false !== $counts ) {
     2553                return apply_filters( 'wp_count_sites', $counts, $network_id );
     2554        }
     2555
     2556        // Query for site statuses
     2557        $query = $wpdb->prepare(
     2558                        "SELECT
     2559                                SUM(public) AS `public`,
     2560                                SUM(archived) AS `archived`,
     2561                                SUM(mature) AS `mature`,
     2562                                SUM(spam) AS `spam`,
     2563                                SUM(deleted) as `deleted`
     2564                        FROM shc_blogs WHERE site_id = %d",
     2565                $network_id );
     2566        $counts  = $wpdb->get_row( $query );
     2567
     2568        wp_cache_set( "sites-{$network_id}", $counts, 'networks' );
     2569
     2570        /**
     2571         * Filter site counts by status for the current network.
     2572         *
     2573         * @since 4.8.x
     2574         *
     2575         * @param object $counts An object containing the current network's site
     2576         *                     counts by status.
     2577         */
     2578        return apply_filters( 'wp_count_sites', $counts, $network_id );
     2579}