Changeset 34875 for trunk/src/wp-includes/class-wp-user-query.php
- Timestamp:
- 10/06/2015 05:39:23 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user-query.php
r34804 r34875 89 89 'blog_id' => $GLOBALS['blog_id'], 90 90 'role' => '', 91 'role__in' => array(), 92 'role__not_in' => array(), 91 93 'meta_key' => '', 92 94 'meta_value' => '', … … 118 120 * for `$orderby` parameter. 119 121 * @since 4.3.0 Added 'has_published_posts' parameter. 120 * @since 4.4.0 Added 'paged' parameter. 122 * @since 4.4.0 Added 'paged', 'role__in', and 'role__not_in' parameters. 'role' parameter was updated to 123 * permit an array or comma-separated list of values. 121 124 * @access public 122 125 * … … 128 131 * 129 132 * @type int $blog_id The site ID. Default is the global blog id. 130 * @type string $role Role name. Default empty. 133 * @type string|array $role An array or a comma-separated list of role names that users must match 134 * to be included in results. Note that this is an inclusive list: users 135 * must match *each* role. Default empty. 136 * @type array $role__in An array of role names. Matched users must have at least one of these 137 * roles. Default empty array. 138 * @type array $role__not_in An array of role names to exclude. Users matching one or more of these 139 * roles will not be included in results. Default empty array. 131 140 * @type string $meta_key User meta key. Default empty. 132 141 * @type string $meta_value User meta value. Default empty. … … 260 269 $this->meta_query->parse_query_vars( $qv ); 261 270 262 $role = '';271 $roles = array(); 263 272 if ( isset( $qv['role'] ) ) { 264 $role = trim( $qv['role'] ); 265 } 266 267 if ( $blog_id && ( $role || is_multisite() ) ) { 268 $cap_meta_query = array(); 269 $cap_meta_query['key'] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; 270 271 if ( $role ) { 272 $cap_meta_query['value'] = '"' . $role . '"'; 273 $cap_meta_query['compare'] = 'like'; 273 if ( is_array( $qv['role'] ) ) { 274 $roles = $qv['role']; 275 } elseif ( is_string( $qv['role'] ) && ! empty( $qv['role'] ) ) { 276 $roles = array_map( 'trim', explode( ',', $qv['role'] ) ); 277 } 278 } 279 280 $role__in = array(); 281 if ( isset( $qv['role__in'] ) ) { 282 $role__in = (array) $qv['role__in']; 283 } 284 285 $role__not_in = array(); 286 if ( isset( $qv['role__not_in'] ) ) { 287 $role__not_in = (array) $qv['role__not_in']; 288 } 289 290 if ( $blog_id && ( ! empty( $roles ) || ! empty( $role__in ) || ! empty( $role__not_in ) || is_multisite() ) ) { 291 $role_queries = array( 'relation' => 'AND' ); 292 $roles_clauses = array( 'relation' => 'AND' ); 293 if ( ! empty( $roles ) ) { 294 foreach ( $roles as $role ) { 295 $roles_clauses[] = array( 296 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 297 'value' => $role, 298 'compare' => 'LIKE', 299 ); 300 } 301 302 // Sanity check: this clause may already have been added to the meta_query. 303 if ( empty( $this->meta_query->clauses ) || ! in_array( $roles_clauses, $this->meta_query_clauses, true ) ) { 304 $role_queries[] = $roles_clauses; 305 } 306 } 307 308 $role__in_clauses = array( 'relation' => 'OR' ); 309 if ( ! empty( $role__in ) ) { 310 foreach ( $role__in as $role ) { 311 $role__in_clauses[] = array( 312 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 313 'value' => $role, 314 'compare' => 'LIKE', 315 ); 316 } 317 318 $role_queries[] = $role__in_clauses; 319 } 320 321 $role__not_in_clauses = array( 'relation' => 'AND' ); 322 if ( ! empty( $role__not_in ) ) { 323 foreach ( $role__not_in as $role ) { 324 $role__not_in_clauses[] = array( 325 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 326 'value' => $role, 327 'compare' => 'NOT LIKE', 328 ); 329 } 330 331 $role_queries[] = $role__not_in_clauses; 274 332 } 275 333 276 334 if ( empty( $this->meta_query->queries ) ) { 277 $this->meta_query->queries = array( $cap_meta_query );278 } else if ( ! in_array( $cap_meta_query, $this->meta_query->queries, true ) ){335 $this->meta_query->queries = $role_queries; 336 } else { 279 337 // Append the cap query to the original queries and reparse the query. 280 338 $this->meta_query->queries = array( 281 339 'relation' => 'AND', 282 array( $this->meta_query->queries, $ cap_meta_query),340 array( $this->meta_query->queries, $role_queries ), 283 341 ); 284 342 }
Note: See TracChangeset
for help on using the changeset viewer.