Ticket #38071: 38071.2.diff
File 38071.2.diff, 7.4 KB (added by , 7 years ago) |
---|
-
wp-admin/includes/class-wp-ms-sites-list-table.php
From 689879846be541dca1ac9f0cdcd2fd95e6f898ee Mon Sep 17 00:00:00 2001 From: Paul Biron <paul@sparrowhawkcomputing.com> Date: Sat, 6 May 2017 16:13:41 -0600 Subject: [PATCH] 38071.2 --- wp-admin/includes/class-wp-ms-sites-list-table.php | 115 ++++++++++++++++++++- wp-admin/network/sites.php | 3 + wp-includes/ms-functions.php | 47 +++++++++ 3 files changed, 164 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..62a2aff 100644
a b 11 11 * Core class used to implement displaying sites in a list table for the network admin. 12 12 * 13 13 * @since 3.1.0 14 * @since 4.8.x Added Site Status views, like on wp-admin/edit.php 14 15 * @access private 15 16 * 16 17 * @see WP_List_Table … … class WP_MS_Sites_List_Table extends WP_List_Table { 21 22 * Site status list. 22 23 * 23 24 * @since 4.3.0 25 * @since 4.8.x Now used to display Site Status views, like on wp-admin/edit.php 24 26 * @access public 25 27 * @var array 26 28 */ … … class WP_MS_Sites_List_Table extends WP_List_Table { 38 40 */ 39 41 public function __construct( $args = array() ) { 40 42 $this->status_list = array( 43 'public' => array( 'site-public', __( 'Public' ) ), 41 44 'archived' => array( 'site-archived', __( 'Archived' ) ), 42 45 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), 43 46 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), … … class WP_MS_Sites_List_Table extends WP_List_Table { 166 169 */ 167 170 $args = apply_filters( 'ms_sites_list_table_query_args', $args ); 168 171 172 if ( isset( $_REQUEST['site_status'] ) && ! empty( $_REQUEST['site_status'] ) ) { 173 $args[$_REQUEST['site_status']] = 1; 174 } 175 169 176 $_sites = get_sites( $args ); 170 177 if ( is_array( $_sites ) ) { 171 178 update_site_cache( $_sites ); … … class WP_MS_Sites_List_Table extends WP_List_Table { 193 200 } 194 201 195 202 /** 203 * Determine if the current view is the "All" view. 204 * 205 * @since 4.8.x 206 * 207 * @return bool true if current view is the "All" view, false otherwise 208 */ 209 protected function is_base_request() { 210 $vars = $_GET; 211 212 return empty( $vars['site_status'] ) || 'all' === $vars['site_status']; 213 } 214 215 /** 216 * Helper to create links to sites.php with params. 217 * 218 * @since 4.8.x 219 * @access protected 220 * 221 * @param array $args URL parameters for the link. 222 * @param string $label Link text. 223 * @param string $class Optional. Class attribute. Default empty string. 224 * @return string The formatted link string. 225 */ 226 protected function get_edit_link( $args, $label, $class = '' ) { 227 $url = add_query_arg( $args, 'sites.php' ); 228 229 $class_html = ''; 230 if ( ! empty( $class ) ) { 231 $class_html = sprintf( 232 ' class="%s"', 233 esc_attr( $class ) 234 ); 235 } 236 237 return sprintf( 238 '<a href="%s"%s>%s</a>', 239 esc_url( $url ), 240 $class_html, 241 $label 242 ); 243 } 244 245 /** 246 * Get an associative array ( id => link ) with the list of views available on this table. 247 * 248 * @since 4.8.x 249 * @return array 250 */ 251 protected function get_views() { 252 $num_sites = wp_count_sites(); 253 $total_sites = get_sites( array( 'count' => true, 'number' => 0, 'network_id' => get_current_network_id() ) ) ; 254 255 $class = ''; 256 if ( $this->is_base_request() ) { 257 $class = 'current'; 258 } 259 260 $all_inner_html = sprintf( 261 _nx( 262 'All <span class="count">(%s)</span>', 263 'All <span class="count">(%s)</span>', 264 $total_sites, 265 'sites' 266 ), 267 number_format_i18n( $total_sites ) 268 ); 269 270 $status_links = array() ; 271 272 $status_links['all'] = $this->get_edit_link( array (), $all_inner_html, $class ); 273 274 foreach ( $this->status_list as $status => $status_name ) { 275 if ( ! $num_sites->{$status} ) { 276 continue; 277 } 278 279 $class = ''; 280 if ( isset( $_REQUEST['site_status'] ) && $status === $_REQUEST['site_status'] ) { 281 $class = 'current'; 282 } 283 284 $status_args = array( 285 'site_status' => $status, 286 ); 287 288 $status_name = $status_name[1]; 289 $status_inner_html = sprintf( 290 _nx( 291 $status_name . ' <span class="count">(%s)</span>', 292 $status_name . ' <span class="count">(%s)</span>', 293 $num_sites->{$status}, 294 'sites' 295 ), 296 number_format_i18n( $num_sites->{$status} ) 297 ); 298 299 $status_links[$status] = $this->get_edit_link( $status_args, $status_inner_html, $class ); 300 } 301 302 return $status_links; 303 } 304 305 /** 196 306 * 197 307 * @return array 198 308 */ … … class WP_MS_Sites_List_Table extends WP_List_Table { 307 417 reset( $this->status_list ); 308 418 309 419 foreach ( $this->status_list as $status => $col ) { 420 if ( isset( $_REQUEST['site_status'] ) && $status === $_REQUEST['site_status'] ) { 421 continue; 422 } 310 423 if ( $blog[ $status ] == 1 ) { 311 424 $blog_states[] = $col[1]; 312 425 } … … class WP_MS_Sites_List_Table extends WP_List_Table { 319 432 foreach ( $blog_states as $state ) { 320 433 ++$i; 321 434 $sep = ( $i == $state_count ) ? '' : ', '; 322 $blog_state .= "<span class=' post-state'>$state$sep</span>";435 $blog_state .= "<span class='site-state'>$state$sep</span>"; 323 436 } 324 437 } 325 438 -
wp-admin/network/sites.php
diff --git a/wp-admin/network/sites.php b/wp-admin/network/sites.php index a0ec407..baa39d0 100644
a b if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { 306 306 307 307 <form method="get" id="ms-search"> 308 308 <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?> 309 <input type="hidden" name="site_status" class="site_status_page" value="<?php echo ! empty( $_REQUEST['site_status'] ) ? esc_attr( $_REQUEST['site_status'] ) : 'all'; ?>" /> 309 310 <input type="hidden" name="action" value="blogs" /> 310 311 </form> 311 312 313 <?php $wp_list_table->views(); ?> 314 312 315 <form id="form-site-list" action="sites.php?action=allblogs" method="post"> 313 316 <?php $wp_list_table->display(); ?> 314 317 </form> -
wp-includes/ms-functions.php
diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index d209435..b1e9b40 100644
a b function get_subdirectory_reserved_names() { 2527 2527 */ 2528 2528 return apply_filters( 'subdirectory_reserved_names', $names ); 2529 2529 } 2530 2531 /** 2532 * Count number of sites with each site status. 2533 * 2534 * @since 4.8.x 2535 * 2536 * @global wpdb $wpdb WordPress database abstraction object. 2537 * 2538 * @return object Number of sites for each status. 2539 */ 2540 function wp_count_sites( $network_id = null ) { 2541 global $wpdb; 2542 2543 if ( is_null( $network_id ) ) { 2544 // Get current network ID 2545 $network_id = get_current_network_id(); 2546 } 2547 2548 // Bail if counts already cached 2549 $counts = wp_cache_get( "sites-{$network_id}", 'networks' ); 2550 if ( false !== $counts ) { 2551 return apply_filters( 'wp_count_sites', $counts, $network_id ); 2552 } 2553 2554 // Query for site stati 2555 $query = $wpdb->prepare( 2556 "SELECT 2557 SUM(public) AS `public`, 2558 SUM(archived) AS `archived`, 2559 SUM(mature) AS `mature`, 2560 SUM(spam) AS `spam`, 2561 SUM(deleted) as `deleted` 2562 FROM $wpdb->blogs WHERE site_id = %d", 2563 $network_id ); 2564 $counts = $wpdb->get_row( $query ); 2565 2566 wp_cache_set( "sites-{$network_id}", $counts, 'networks' ); 2567 2568 /** 2569 * Filter site counts by status for the current network. 2570 * 2571 * @since 4.8.x 2572 * 2573 * @param object $counts An object containing site counts by status for $network_id. 2574 */ 2575 return apply_filters( 'wp_count_sites', $counts, $network_id ); 2576 }