diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/class-wp-ms-sites-list-table.php --- a/wp/wp-admin/includes/class-wp-ms-sites-list-table.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/includes/class-wp-ms-sites-list-table.php Tue Dec 15 13:49:49 2020 +0100 @@ -62,15 +62,15 @@ * * @since 3.1.0 * + * @global string $mode List table view mode. * @global string $s - * @global string $mode - * @global wpdb $wpdb + * @global wpdb $wpdb WordPress database abstraction object. */ public function prepare_items() { - global $s, $mode, $wpdb; + global $mode, $s, $wpdb; if ( ! empty( $_REQUEST['mode'] ) ) { - $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; + $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list'; set_user_setting( 'sites_list_mode', $mode ); } else { $mode = get_user_setting( 'sites_list_mode', 'list' ); @@ -93,10 +93,12 @@ */ if ( ! $s && wp_is_large_network() ) { if ( ! isset( $_REQUEST['orderby'] ) ) { - $_GET['orderby'] = $_REQUEST['orderby'] = ''; + $_GET['orderby'] = ''; + $_REQUEST['orderby'] = ''; } if ( ! isset( $_REQUEST['order'] ) ) { - $_GET['order'] = $_REQUEST['order'] = 'DESC'; + $_GET['order'] = 'DESC'; + $_REQUEST['order'] = 'DESC'; } } @@ -112,7 +114,7 @@ preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { - // IPv4 address + // IPv4 address. $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) ); $reg_blog_ids = $wpdb->get_col( $sql ); @@ -131,7 +133,7 @@ $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; if ( 'registered' === $order_by ) { - // registered is a valid field name. + // 'registered' is a valid field name. } elseif ( 'lastupdated' === $order_by ) { $order_by = 'last_updated'; } elseif ( 'blogname' === $order_by ) { @@ -158,6 +160,12 @@ $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. * @@ -200,6 +208,80 @@ } /** + * Gets links to filter sites by status. + * + * @since 5.3.0 + * + * @return array + */ + protected function get_views() { + $counts = wp_count_sites(); + + $statuses = array( + /* translators: %s: Number of sites. */ + 'all' => _nx_noop( + 'All (%s)', + 'All (%s)', + 'sites' + ), + + /* translators: %s: Number of sites. */ + 'public' => _n_noop( + 'Public (%s)', + 'Public (%s)' + ), + + /* translators: %s: Number of sites. */ + 'archived' => _n_noop( + 'Archived (%s)', + 'Archived (%s)' + ), + + /* translators: %s: Number of sites. */ + 'mature' => _n_noop( + 'Mature (%s)', + 'Mature (%s)' + ), + + /* translators: %s: Number of sites. */ + 'spam' => _nx_noop( + 'Spam (%s)', + 'Spam (%s)', + 'sites' + ), + + /* translators: %s: Number of sites. */ + 'deleted' => _n_noop( + 'Deleted (%s)', + 'Deleted (%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 */ protected function get_bulk_actions() { @@ -207,8 +289,8 @@ if ( current_user_can( 'delete_sites' ) ) { $actions['delete'] = __( 'Delete' ); } - $actions['spam'] = _x( 'Mark as Spam', 'site' ); - $actions['notspam'] = _x( 'Not Spam', 'site' ); + $actions['spam'] = _x( 'Mark as spam', 'site' ); + $actions['notspam'] = _x( 'Not spam', 'site' ); return $actions; } @@ -216,7 +298,7 @@ /** * @global string $mode List table view mode. * - * @param string $which + * @param string $which The location of the pagination nav markup: 'top' or 'bottom'. */ protected function pagination( $which ) { global $mode; @@ -229,6 +311,48 @@ } /** + * Extra controls to be displayed between bulk actions and pagination. + * + * @since 5.3.0 + * + * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. + */ + protected function extra_tablenav( $which ) { + ?> +