Ticket #37392: 37392.7.patch
File 37392.7.patch, 4.9 KB (added by , 6 years ago) |
---|
-
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 { 157 157 } else { 158 158 $args['no_found_rows'] = false; 159 159 } 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 } 160 165 161 166 /** 162 167 * Filters the arguments for the site query in the sites list table. … … class WP_MS_Sites_List_Table extends WP_List_Table { 198 203 _e( 'No sites found.' ); 199 204 } 200 205 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 201 250 /** 202 251 * @return array 203 252 */ -
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'] ) ) { 355 355 356 356 <hr class="wp-header-end"> 357 357 358 <?php $wp_list_table->views(); ?> 359 358 360 <?php echo $msg; ?> 359 361 360 362 <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 1537 1537 1538 1538 update_posts_count(); 1539 1539 } 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 */ 1553 function 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 }