Index: src/wp-includes/class-wp-site-query.php
===================================================================
--- src/wp-includes/class-wp-site-query.php	(revision 41950)
+++ src/wp-includes/class-wp-site-query.php	(working copy)
@@ -143,7 +143,7 @@
 		$this->query_var_defaults = array(
 			'fields'            => '',
 			'ID'                => '',
-			'site__in'          => '',
+			'site__in'          => array(),
 			'site__not_in'      => '',
 			'number'            => 100,
 			'offset'            => '',
@@ -151,13 +151,13 @@
 			'orderby'           => 'id',
 			'order'             => 'ASC',
 			'network_id'        => 0,
-			'network__in'       => '',
+			'network__in'       => array(),
 			'network__not_in'   => '',
 			'domain'            => '',
-			'domain__in'        => '',
+			'domain__in'        => array(),
 			'domain__not_in'    => '',
 			'path'              => '',
-			'path__in'          => '',
+			'path__in'          => array(),
 			'path__not_in'      => '',
 			'public'            => null,
 			'archived'          => null,
@@ -165,7 +165,7 @@
 			'spam'              => null,
 			'deleted'           => null,
 			'lang_id'           => null,
-			'lang__in'          => '',
+			'lang__in'          => array(),
 			'lang__not_in'      => '',
 			'search'            => '',
 			'search_columns'    => array(),
@@ -206,6 +206,42 @@
 	}
 
 	/**
+	 * @param string $query
+	 */
+	public function tidy_query( $query = '' ) {
+		if ( empty( $query ) ) {
+			$query = $this->query_vars;
+		}
+		$query = wp_parse_args( $query );
+
+		$list = array(
+			'ID'         => 'site__in',
+			'network_id' => 'network__in',
+			'domain'     => 'domain__in',
+			'path'       => 'path__in',
+			'lang_id'    => 'lang__in'
+		);
+
+		foreach ( $list as $key => $value ) {
+			if ( empty( $query[ $key ] ) ) {
+				unset( $query[ $key ] );
+				continue;
+			}
+			if ( empty( $query[ $value ] ) ||  ! is_array( $query[ $value ] ) ) {
+				$query[ $value ] = array();
+			}
+
+			if ( ! in_array( $query[ $key ], $query[ $value ] ) ) {
+				$query[ $value ][] = $query[ $key ];
+			}
+
+			unset( $query[ $key ] );
+		}
+		
+		$this->query_vars = $query;
+	}
+
+	/**
 	 * Sets up the WordPress query for retrieving sites.
 	 *
 	 * @since 4.6.0
@@ -240,6 +276,8 @@
 		 */
 		do_action_ref_array( 'pre_get_sites', array( &$this ) );
 
+		$this->tidy_query();
+
 		// $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
 		$_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
 
@@ -388,12 +426,6 @@
 		}
 
 		// Parse site IDs for an IN clause.
-		$site_id = absint( $this->query_vars['ID'] );
-		if ( ! empty( $site_id ) ) {
-			$this->sql_clauses['where']['ID'] = $wpdb->prepare( 'blog_id = %d', $site_id );
-		}
-
-		// Parse site IDs for an IN clause.
 		if ( ! empty( $this->query_vars['site__in'] ) ) {
 			$this->sql_clauses['where']['site__in'] = "blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )';
 		}
@@ -403,12 +435,6 @@
 			$this->sql_clauses['where']['site__not_in'] = "blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )';
 		}
 
-		$network_id = absint( $this->query_vars['network_id'] );
-
-		if ( ! empty( $network_id ) ) {
-			$this->sql_clauses['where']['network_id'] = $wpdb->prepare( 'site_id = %d', $network_id );
-		}
-
 		// Parse site network IDs for an IN clause.
 		if ( ! empty( $this->query_vars['network__in'] ) ) {
 			$this->sql_clauses['where']['network__in'] = 'site_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )';
@@ -419,10 +445,6 @@
 			$this->sql_clauses['where']['network__not_in'] = 'site_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )';
 		}
 
-		if ( ! empty( $this->query_vars['domain'] ) ) {
-			$this->sql_clauses['where']['domain'] = $wpdb->prepare( 'domain = %s', $this->query_vars['domain'] );
-		}
-
 		// Parse site domain for an IN clause.
 		if ( is_array( $this->query_vars['domain__in'] ) ) {
 			$this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )";
@@ -433,10 +455,6 @@
 			$this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";
 		}
 
-		if ( ! empty( $this->query_vars['path'] ) ) {
-			$this->sql_clauses['where']['path'] = $wpdb->prepare( 'path = %s', $this->query_vars['path'] );
-		}
-
 		// Parse site path for an IN clause.
 		if ( is_array( $this->query_vars['path__in'] ) ) {
 			$this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )";
@@ -472,11 +490,6 @@
 			$this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public );
 		}
 
-		if ( is_numeric( $this->query_vars['lang_id'] ) ) {
-			$lang_id = absint( $this->query_vars['lang_id'] );
-			$this->sql_clauses['where']['lang_id'] = $wpdb->prepare( "lang_id = %d ", $lang_id );
-		}
-
 		// Parse site language IDs for an IN clause.
 		if ( ! empty( $this->query_vars['lang__in'] ) ) {
 			$this->sql_clauses['where']['lang__in'] = 'lang_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['lang__in'] ) ) . ' )';
