From a93ec5244d62250c913db7a4ef1f14ee1e115a41 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Tue, 6 Oct 2015 20:58:24 +0000 Subject: [PATCH] Revert [34875] due to unintentional breaking change WordPress.org was taken down due to as Otto42 describes: The previous version of this function added the query piece for the meta key = blog_id.capabilities, regardless of whether or not a role was requested. This limits the users returned to those with some defined role on this particular multisite instance. See #22212 Built from https://develop.svn.wordpress.org/trunk@34880 git-svn-id: http://core.svn.wordpress.org/trunk@34845 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-user-query.php | 84 +++++------------------------ wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 72 deletions(-) diff --git a/wp-includes/class-wp-user-query.php b/wp-includes/class-wp-user-query.php index 756d0974d8..1bc08aa491 100644 --- a/wp-includes/class-wp-user-query.php +++ b/wp-includes/class-wp-user-query.php @@ -88,8 +88,6 @@ class WP_User_Query { $defaults = array( 'blog_id' => $GLOBALS['blog_id'], 'role' => '', - 'role__in' => array(), - 'role__not_in' => array(), 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', @@ -119,8 +117,7 @@ class WP_User_Query { * @since 4.2.0 Added 'meta_value_num' support for `$orderby` parameter. Added multi-dimensional array syntax * for `$orderby` parameter. * @since 4.3.0 Added 'has_published_posts' parameter. - * @since 4.4.0 Added 'paged', 'role__in', and 'role__not_in' parameters. 'role' parameter was updated to - * permit an array or comma-separated list of values. + * @since 4.4.0 Added 'paged' parameter. * @access public * * @global wpdb $wpdb @@ -130,13 +127,7 @@ class WP_User_Query { * Optional. Array or string of Query parameters. * * @type int $blog_id The site ID. Default is the global blog id. - * @type string|array $role An array or a comma-separated list of role names that users must match - * to be included in results. Note that this is an inclusive list: users - * must match *each* role. Default empty. - * @type array $role__in An array of role names. Matched users must have at least one of these - * roles. Default empty array. - * @type array $role__not_in An array of role names to exclude. Users matching one or more of these - * roles will not be included in results. Default empty array. + * @type string $role Role name. Default empty. * @type string $meta_key User meta key. Default empty. * @type string $meta_value User meta value. Default empty. * @type string $meta_compare Comparison operator to test the `$meta_value`. Accepts '=', '!=', @@ -268,76 +259,27 @@ class WP_User_Query { $this->meta_query = new WP_Meta_Query(); $this->meta_query->parse_query_vars( $qv ); - $roles = array(); + $role = ''; if ( isset( $qv['role'] ) ) { - if ( is_array( $qv['role'] ) ) { - $roles = $qv['role']; - } elseif ( is_string( $qv['role'] ) && ! empty( $qv['role'] ) ) { - $roles = array_map( 'trim', explode( ',', $qv['role'] ) ); - } + $role = trim( $qv['role'] ); } - $role__in = array(); - if ( isset( $qv['role__in'] ) ) { - $role__in = (array) $qv['role__in']; - } + if ( $blog_id && ( $role || is_multisite() ) ) { + $cap_meta_query = array(); + $cap_meta_query['key'] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; - $role__not_in = array(); - if ( isset( $qv['role__not_in'] ) ) { - $role__not_in = (array) $qv['role__not_in']; - } - - if ( $blog_id && ( ! empty( $roles ) || ! empty( $role__in ) || ! empty( $role__not_in ) || is_multisite() ) ) { - $role_queries = array( 'relation' => 'AND' ); - $roles_clauses = array( 'relation' => 'AND' ); - if ( ! empty( $roles ) ) { - foreach ( $roles as $role ) { - $roles_clauses[] = array( - 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', - 'value' => $role, - 'compare' => 'LIKE', - ); - } - - // Sanity check: this clause may already have been added to the meta_query. - if ( empty( $this->meta_query->clauses ) || ! in_array( $roles_clauses, $this->meta_query_clauses, true ) ) { - $role_queries[] = $roles_clauses; - } - } - - $role__in_clauses = array( 'relation' => 'OR' ); - if ( ! empty( $role__in ) ) { - foreach ( $role__in as $role ) { - $role__in_clauses[] = array( - 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', - 'value' => $role, - 'compare' => 'LIKE', - ); - } - - $role_queries[] = $role__in_clauses; - } - - $role__not_in_clauses = array( 'relation' => 'AND' ); - if ( ! empty( $role__not_in ) ) { - foreach ( $role__not_in as $role ) { - $role__not_in_clauses[] = array( - 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', - 'value' => $role, - 'compare' => 'NOT LIKE', - ); - } - - $role_queries[] = $role__not_in_clauses; + if ( $role ) { + $cap_meta_query['value'] = '"' . $role . '"'; + $cap_meta_query['compare'] = 'like'; } if ( empty( $this->meta_query->queries ) ) { - $this->meta_query->queries = $role_queries; - } else { + $this->meta_query->queries = array( $cap_meta_query ); + } elseif ( ! in_array( $cap_meta_query, $this->meta_query->queries, true ) ) { // Append the cap query to the original queries and reparse the query. $this->meta_query->queries = array( 'relation' => 'AND', - array( $this->meta_query->queries, $role_queries ), + array( $this->meta_query->queries, $cap_meta_query ), ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 37355c116b..49f981f591 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34879'; +$wp_version = '4.4-alpha-34880'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.