From 1c69792253c0662b66c38bbed68e89cb3b39b7b4 Mon Sep 17 00:00:00 2001 From: John James Jacoby Date: Mon, 23 Sep 2019 17:50:22 +0000 Subject: [PATCH] Multisite/Sites: supplemental commit to r46251. This commit adds the links to the list-table class itself (that were missed in r46251.) See #37392. Props pbiron, thomaswm. git-svn-id: https://develop.svn.wordpress.org/trunk@46254 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-ms-sites-list-table.php | 50 +++++++++++++++++++ 1 file changed, 50 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 519a57d8c4..5147139835 100644 --- a/src/wp-admin/includes/class-wp-ms-sites-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-sites-list-table.php @@ -160,6 +160,12 @@ class WP_MS_Sites_List_Table extends WP_List_Table { $args['no_found_rows'] = false; } + // Take into account the role the user has selected. + $status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : ''; + if ( in_array( $status, array( 'public', 'archived', 'mature', 'spam', 'deleted' ), true ) ) { + $args[ $status ] = 1; + } + /** * Filters the arguments for the site query in the sites list table. * @@ -201,6 +207,50 @@ class WP_MS_Sites_List_Table extends WP_List_Table { _e( 'No sites found.' ); } + /** + * Gets links to filter sites by status. + * + * @since 5.3.0 + * + * @return array + * + */ + protected function get_views() { + $counts = wp_count_sites(); + + $statuses = array( + 'all' => _n_noop( 'All (%s)', 'All (%1$s)' ), + 'public' => _n_noop( 'Public (%s)', 'Public (%1$s)' ), + 'archived' => _n_noop( 'Archived (%1$s)', 'Archived (%1$s)' ), + 'mature' => _n_noop( 'Mature (%1$s)', 'Mature (%1$s)' ), + 'spam' => _n_noop( 'Spam (%1$s)', 'Spam (%1$s)' ), + 'deleted' => _n_noop( 'Deleted (%1$s)', 'Deleted (%1$s)' ), + ); + + $view_links = array(); + $requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : ''; + $url = 'sites.php'; + + foreach ( $statuses as $status => $label_count ) { + $current_link_attributes = $requested_status === $status || ( $requested_status === '' && 'all' === $status ) + ? ' class="current" aria-current="page"' + : ''; + if ( (int) $counts[ $status ] > 0 ) { + $label = sprintf( translate_nooped_plural( $label_count, $counts[ $status ] ), number_format_i18n( $counts[ $status ] ) ); + $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url ); + + $view_links[ $status ] = sprintf( + '%3$s', + esc_url( $full_url ), + $current_link_attributes, + $label + ); + } + } + + return $view_links; + } + /** * @return array */