Index: wp-includes/user.php
===================================================================
--- wp-includes/user.php	(revision 17649)
+++ wp-includes/user.php	(working copy)
@@ -501,8 +501,6 @@
 			$qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
 		}
 
-		_parse_meta_query( $qv );
-
 		$role = trim( $qv['role'] );
 
 		if ( $blog_id && ( $role || is_multisite() ) ) {
@@ -517,8 +515,11 @@
 			$qv['meta_query'][] = $cap_meta_query;
 		}
 
-		if ( !empty( $qv['meta_query'] ) ) {
-			$clauses = call_user_func_array( '_get_meta_sql', array( $qv['meta_query'], 'user', $wpdb->users, 'ID', &$this ) );
+		$meta_query = new WP_Meta_Query();
+		$meta_query->parse_query_vars( $qv );
+
+		if ( !empty( $meta_query->queries ) ) {
+			$clauses = call_user_func_array( array( $meta_query, 'get_sql' ), array( 'user', $wpdb->users, 'ID', &$this ) );
 			$this->query_from .= $clauses['join'];
 			$this->query_where .= $clauses['where'];
 		}
Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php	(revision 17649)
+++ wp-includes/query.php	(working copy)
@@ -840,7 +840,7 @@
 	var $query_vars = array();
 
 	/**
-	 * Taxonomy query, as passed to get_tax_sql()
+	 * Taxonomy query container
 	 *
 	 * @since 3.1.0
 	 * @access public
@@ -849,6 +849,15 @@
 	var $tax_query;
 
 	/**
+	 * Metadata query container
+	 *
+	 * @since 3.2
+	 * @access public
+	 * @var object WP_Meta_Query
+	 */
+	var $meta_query;
+
+	/**
 	 * Holds the data for a single object that is queried.
 	 *
 	 * Holds the contents of a post, page, category, attachment.
@@ -1525,7 +1534,8 @@
 			}
 			unset( $tax_query );
 
-			_parse_meta_query( $qv );
+			$this->meta_query = new WP_Meta_Query();
+			$this->meta_query->parse_query_vars( $qv );
 
 			if ( empty($qv['author']) || ($qv['author'] == '0') ) {
 				$this->is_author = false;
@@ -2231,7 +2241,7 @@
 			}
 		}
 
-		if ( !empty( $this->tax_query->queries ) || !empty( $q['meta_key'] ) ) {
+		if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) {
 			$groupby = "{$wpdb->posts}.ID";
 		}
 
@@ -2474,8 +2484,10 @@
 				$q['meta_query'] = array_merge( $_meta_query, $q['meta_query'] );
 		}
 
-		if ( !empty( $q['meta_query'] ) ) {
-			$clauses = call_user_func_array( '_get_meta_sql', array( $q['meta_query'], 'post', $wpdb->posts, 'ID', &$this) );
+		$this->meta_query->parse_query_vars( $q );
+
+		if ( !empty( $this->meta_query->queries ) ) {
+			$clauses = call_user_func_array( array( $this->meta_query, 'get_sql' ), array( 'post', $wpdb->posts, 'ID', &$this ) );
 			$join .= $clauses['join'];
 			$where .= $clauses['where'];
 		}
Index: wp-includes/meta.php
===================================================================
--- wp-includes/meta.php	(revision 17649)
+++ wp-includes/meta.php	(working copy)
@@ -353,120 +353,143 @@
 }
 
 /**
- * Given a meta query, generates SQL clauses to be appended to a main query
+ * Container class for a multiple metadata query.
  *
- * @since 3.1.0
- * @access private
- *
- * @param array $meta_query List of metadata queries. A single query is an associative array:
- * - 'key' string The meta key
- * - 'value' string|array The meta value
- * - 'compare' (optional) string How to compare the key to the value.
- *		Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
- *		Default: '='
- * - 'type' string (optional) The type of the value.
- *		Possible values: 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'.
- *		Default: 'CHAR'
- *
- * @param string $type Type of meta
- * @param string $primary_table
- * @param string $primary_id_column
- * @param object $context (optional) The main query object
- * @return array( 'join' => $join_sql, 'where' => $where_sql )
+ * @since 3.2
  */
-function _get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context = null ) {
-	global $wpdb;
+class WP_Meta_Query {
 
-	if ( ! $meta_table = _get_meta_table( $type ) )
-		return false;
+	/**
+	 * List of metadata queries. A single query is an associative array:
+	 * - 'key' string The meta key
+	 * - 'value' string|array The meta value
+	 * - 'compare' (optional) string How to compare the key to the value.
+	 *		Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
+	 *		Default: '='
+	 * - 'type' string (optional) The type of the value.
+	 *		Possible values: 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'.
+	 *		Default: 'CHAR'
+	 *
+	 * @since 3.2
+	 * @access public
+	 * @var array
+	 */
+	public $queries = array();
 
-	$meta_id_column = esc_sql( $type . '_id' );
+	/**
+	 * Constructor
+	 *
+	 * @param array (optional) $meta_query A meta query
+	 */
+	function __construct( $meta_query = false ) {
+		if ( $meta_query )
+			$this->queries = $meta_query;
+	}
 
-	$join = '';
-	$where = '';
-	$i = 0;
-	foreach ( $meta_query as $q ) {
-		$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
-		$meta_value = isset( $q['value'] ) ? $q['value'] : '';
-		$meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
-		$meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
+	/**
+	 * Populates the $queries property by looking for 'meta_*' query variables
+	 *
+	 * @since 3.2
+	 * @access public
+	 *
+	 * @param array $qv The query variables
+	 */
+	function parse_query_vars( $qv ) {
+		$this->queries = array();
 
-		if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
-			$meta_compare = '=';
+		// Simple query needs to be first for orderby=meta_value to work correctly
+		foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {
+			if ( !empty( $qv[ "meta_$key" ] ) )
+				$this->queries[0][ $key ] = $qv[ "meta_$key" ];
+		}
 
-		if ( 'NUMERIC' == $meta_type )
-			$meta_type = 'SIGNED';
-		elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )
-			$meta_type = 'CHAR';
+		if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
+			$this->queries = array_merge( $this->queries, $qv['meta_query'] );
+		}
+	}
 
-		if ( empty( $meta_key ) && empty( $meta_value ) )
-			continue;
+	/**
+	 * Generates SQL clauses to be appended to a main query.
+	 *
+	 * @since 3.2
+	 * @access public
+	 *
+	 * @param string $type Type of meta
+	 * @param string $primary_table
+	 * @param string $primary_id_column
+	 * @param object $context (optional) The main query object
+	 * @return array( 'join' => $join_sql, 'where' => $where_sql )
+	 */
+	function get_sql( $type, $primary_table, $primary_id_column, $context = null ) {
+		global $wpdb;
 
-		$alias = $i ? 'mt' . $i : $meta_table;
+		if ( ! $meta_table = _get_meta_table( $type ) )
+			return false;
 
-		$join .= "\nINNER JOIN $meta_table";
-		$join .= $i ? " AS $alias" : '';
-		$join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
+		$meta_id_column = esc_sql( $type . '_id' );
 
-		$i++;
+		$join = '';
+		$where = '';
+		$i = 0;
+		foreach ( $this->queries as $q ) {
+			$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
+			$meta_value = isset( $q['value'] ) ? $q['value'] : '';
+			$meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
+			$meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
 
-		if ( !empty( $meta_key ) )
-			$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
+			if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
+				$meta_compare = '=';
 
-		if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
-			if ( ! is_array( $meta_value ) )
-				$meta_value = preg_split( '/[,\s]+/', $meta_value );
-		} else {
-			$meta_value = trim( $meta_value );
-		}
+			if ( 'NUMERIC' == $meta_type )
+				$meta_type = 'SIGNED';
+			elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )
+				$meta_type = 'CHAR';
 
-		if ( empty( $meta_value ) )
-			continue;
+			if ( empty( $meta_key ) && empty( $meta_value ) )
+				continue;
 
-		if ( 'IN' == substr( $meta_compare, -2) ) {
-			$meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')';
-		} elseif ( 'BETWEEN' == substr( $meta_compare, -7) ) {
-			$meta_value = array_slice( $meta_value, 0, 2 );
-			$meta_compare_string = '%s AND %s';
-		} elseif ( 'LIKE' == substr( $meta_compare, -4 ) ) {
-			$meta_value = '%' . like_escape( $meta_value ) . '%';
-			$meta_compare_string = '%s';
-		} else {
-			$meta_compare_string = '%s';
-		}
+			$alias = $i ? 'mt' . $i : $meta_table;
 
-		// @todo Temporary hack to support empty values. Do not use outside of core.
-		if ( '_wp_zero_value' == $meta_value )
-			$meta_value = 0;
+			$join .= "\nINNER JOIN $meta_table";
+			$join .= $i ? " AS $alias" : '';
+			$join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
 
-		$where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value );
-	}
+			$i++;
 
-	return apply_filters_ref_array( 'get_meta_sql', array( compact( 'join', 'where' ), $meta_query, $type, $primary_table, $primary_id_column, &$context ) );
-}
+			if ( !empty( $meta_key ) )
+				$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
 
-/**
- * Populates the $meta_query property
- *
- * @access private
- * @since 3.1.0
- *
- * @param array $qv The query variables
- */
-function _parse_meta_query( &$qv ) {
-	$meta_query = array();
+			if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
+				if ( ! is_array( $meta_value ) )
+					$meta_value = preg_split( '/[,\s]+/', $meta_value );
+			} else {
+				$meta_value = trim( $meta_value );
+			}
 
-	// Simple query needs to be first for orderby=meta_value to work correctly
-	foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {
-		if ( !empty( $qv[ "meta_$key" ] ) )
-			$meta_query[0][ $key ] = $qv[ "meta_$key" ];
-	}
+			if ( empty( $meta_value ) )
+				continue;
 
-	if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
-		$meta_query = array_merge( $meta_query, $qv['meta_query'] );
+			if ( 'IN' == substr( $meta_compare, -2) ) {
+				$meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')';
+			} elseif ( 'BETWEEN' == substr( $meta_compare, -7) ) {
+				$meta_value = array_slice( $meta_value, 0, 2 );
+				$meta_compare_string = '%s AND %s';
+			} elseif ( 'LIKE' == substr( $meta_compare, -4 ) ) {
+				$meta_value = '%' . like_escape( $meta_value ) . '%';
+				$meta_compare_string = '%s';
+			} else {
+				$meta_compare_string = '%s';
+			}
+
+			// @todo Temporary hack to support empty values. Do not use outside of core.
+			if ( '_wp_zero_value' == $meta_value )
+				$meta_value = 0;
+
+			$where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value );
+		}
+
+		return apply_filters_ref_array( 'get_meta_sql', array( compact( 'join', 'where' ), $this->queries, $type, $primary_table, $primary_id_column, $context ) );
 	}
-
-	$qv['meta_query'] = $meta_query;
 }
 
 /**
@@ -488,4 +511,5 @@
 
 	return $wpdb->$table_name;
 }
+
 ?>
