Changeset 34880 for trunk/src/wp-includes/class-wp-user-query.php
- Timestamp:
- 10/06/2015 08:57:35 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user-query.php
r34875 r34880 89 89 'blog_id' => $GLOBALS['blog_id'], 90 90 'role' => '', 91 'role__in' => array(),92 'role__not_in' => array(),93 91 'meta_key' => '', 94 92 'meta_value' => '', … … 120 118 * for `$orderby` parameter. 121 119 * @since 4.3.0 Added 'has_published_posts' 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. 120 * @since 4.4.0 Added 'paged' parameter. 124 121 * @access public 125 122 * … … 131 128 * 132 129 * @type int $blog_id The site ID. Default is the global blog id. 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. 130 * @type string $role Role name. Default empty. 140 131 * @type string $meta_key User meta key. Default empty. 141 132 * @type string $meta_value User meta value. Default empty. … … 269 260 $this->meta_query->parse_query_vars( $qv ); 270 261 271 $role s = array();262 $role = ''; 272 263 if ( isset( $qv['role'] ) ) { 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; 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'; 332 274 } 333 275 334 276 if ( empty( $this->meta_query->queries ) ) { 335 $this->meta_query->queries = $role_queries;336 } else {277 $this->meta_query->queries = array( $cap_meta_query ); 278 } elseif ( ! in_array( $cap_meta_query, $this->meta_query->queries, true ) ) { 337 279 // Append the cap query to the original queries and reparse the query. 338 280 $this->meta_query->queries = array( 339 281 'relation' => 'AND', 340 array( $this->meta_query->queries, $ role_queries),282 array( $this->meta_query->queries, $cap_meta_query ), 341 283 ); 342 284 }
Note: See TracChangeset
for help on using the changeset viewer.