From 6b7d7467e08ce061afbc2791255b38e9e0b3c3f7 Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Tue, 4 Jun 2019 14:31:56 -0600
Subject: [PATCH] Add a extra_tablenav() method to WP_MS_Sites_List_Table,
 which adds the new restrict_manage_sites and manage_sites_extra_tablenav
 filters.

---
 .../includes/class-wp-ms-sites-list-table.php | 42 +++++++++++++++++++
 src/wp-admin/network/sites.php                | 14 ++++---
 2 files changed, 50 insertions(+), 6 deletions(-)

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 c9399b220b..276ffdecc0 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
@@ -228,6 +228,48 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
 		}
 	}
 
+	/**
+	 * Extra controls to be displayed between bulk actions and pagination.
+	 *
+	 * @since 5.3.0
+	 *
+	 * @param string $which
+	 */
+	protected function extra_tablenav( $which ) {
+		?>
+		<div class="alignleft actions">
+		<?php
+		if ( 'top' === $which ) {
+			ob_start();
+
+			/**
+			 * Fires before the Filter button on the MS sites list table.
+			 *
+			 * @since 5.3.0
+			 *
+			 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
+			 */
+			do_action( 'restrict_manage_sites', $which );
+			$output = ob_get_clean();
+			if ( ! empty( $output ) ) {
+				echo $output;
+				submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'site-query-submit' ) );
+			}
+		}
+		?>
+		</div>
+		<?php
+		/**
+		 * Fires immediately following the closing "actions" div in the tablenav for the
+		 * MS sites list table.
+		 *
+		 * @since 5.3.0
+		 *
+		 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
+		 */
+		do_action( 'manage_sites_extra_tablenav', $which );
+	}
+
 	/**
 	 * @return array
 	 */
diff --git a/src/wp-admin/network/sites.php b/src/wp-admin/network/sites.php
index 6c2de15866..2794d9f849 100644
--- a/src/wp-admin/network/sites.php
+++ b/src/wp-admin/network/sites.php
@@ -215,14 +215,16 @@ if ( isset( $_GET['action'] ) ) {
 					wp_safe_redirect( $redirect_to );
 					exit();
 				}
-			} else {
-				$location = network_admin_url( 'sites.php' );
-				if ( ! empty( $_REQUEST['paged'] ) ) {
-					$location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
-				}
-				wp_redirect( $location );
+			}
+			elseif ( ! empty( $_POST['_wp_http_referer'] ) ) {
+				// process query defined by WP_MS_Site_List_Table::extra_table_nav().
+				$query_args = $_POST;
+				unset( $query_args['_wp_http_referer'], $query_args['_wpnonce'] );
+
+				wp_safe_redirect( add_query_arg( $query_args, network_admin_url( 'sites.php' ) ) );
 				exit();
 			}
+
 			break;
 
 		case 'archiveblog':
-- 
2.19.0.windows.1

