From 73f6a574b7753e3224b5ac6a5a55d6da8c614db4 Mon Sep 17 00:00:00 2001 From: Konstantin Kovshenin Date: Wed, 29 Oct 2014 21:41:22 +0000 Subject: [PATCH] Use a nested meta query when querying by role in `WP_User_Query`. If a user query includes a meta query together with a role argument, nest the original meta query and append the role meta query with an AND relationship. fixes #23849, #27026. Built from https://develop.svn.wordpress.org/trunk@30094 git-svn-id: http://core.svn.wordpress.org/trunk@30094 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 18 +++++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 15523ec80e..1b2a692bed 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -715,6 +715,9 @@ class WP_User_Query { $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query } + $meta_query = new WP_Meta_Query(); + $meta_query->parse_query_vars( $qv ); + $role = ''; if ( isset( $qv['role'] ) ) $role = trim( $qv['role'] ); @@ -728,13 +731,18 @@ class WP_User_Query { $cap_meta_query['compare'] = 'like'; } - if ( empty( $qv['meta_query'] ) || ! in_array( $cap_meta_query, $qv['meta_query'], true ) ) { - $qv['meta_query'][] = $cap_meta_query; + if ( empty( $meta_query->queries ) ) { + $meta_query->queries = array( $cap_meta_query ); + } elseif ( ! in_array( $cap_meta_query, $meta_query->queries, true ) ) { + // Append the cap query to the original queries and reparse the query. + $meta_query->queries = array( + 'relation' => 'AND', + array( $meta_query->queries, $cap_meta_query ), + ); } - } - $meta_query = new WP_Meta_Query(); - $meta_query->parse_query_vars( $qv ); + $meta_query->parse_query_vars( $meta_query->queries ); + } if ( !empty( $meta_query->queries ) ) { $clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $this ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 62a126c9d3..b9691834a9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-alpha-30093'; +$wp_version = '4.1-alpha-30094'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.