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
This commit is contained in:
parent
beaa3f6928
commit
73f6a574b7
|
@ -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 );
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue