Changeset 37360
- Timestamp:
- 05/04/2016 06:56:58 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user-query.php
r36417 r37360 256 256 } 257 257 258 if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) {259 $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';260 $qv['meta_value'] = 0;261 $qv['meta_compare'] = '!=';262 $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query263 }264 265 258 if ( $qv['has_published_posts'] && $blog_id ) { 266 259 if ( true === $qv['has_published_posts'] ) { … … 281 274 $this->meta_query = new WP_Meta_Query(); 282 275 $this->meta_query->parse_query_vars( $qv ); 276 277 if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) { 278 $who_query = array( 279 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'user_level', 280 'value' => 0, 281 'compare' => '!=', 282 ); 283 284 // Prevent extra meta query. 285 $qv['blog_id'] = $blog_id = 0; 286 287 if ( empty( $this->meta_query->queries ) ) { 288 $this->meta_query->queries = array( $who_query ); 289 } else { 290 // Append the cap query to the original queries and reparse the query. 291 $this->meta_query->queries = array( 292 'relation' => 'AND', 293 array( $this->meta_query->queries, $who_query ), 294 ); 295 } 296 297 $this->meta_query->parse_query_vars( $this->meta_query->queries ); 298 } 283 299 284 300 $roles = array(); -
trunk/tests/phpunit/tests/user/query.php
r37359 r37360 694 694 ) 695 695 ), 696 ) ); 697 698 $found = wp_list_pluck( $q->get_results(), 'ID' ); 699 700 $this->assertNotContains( self::$author_ids[0], $found ); 701 $this->assertContains( self::$author_ids[1], $found ); 702 $this->assertNotContains( self::$author_ids[2], $found ); 703 } 704 705 /** 706 * @ticket 36724 707 */ 708 public function test_who_authors_should_work_alongside_meta_params() { 709 if ( ! is_multisite() ) { 710 $this->markTestSkipped( __METHOD__ . ' requires multisite.' ); 711 } 712 713 $b = self::factory()->blog->create(); 714 715 add_user_to_blog( $b, self::$author_ids[0], 'subscriber' ); 716 add_user_to_blog( $b, self::$author_ids[1], 'author' ); 717 add_user_to_blog( $b, self::$author_ids[2], 'editor' ); 718 719 add_user_meta( self::$author_ids[1], 'foo', 'bar' ); 720 add_user_meta( self::$author_ids[2], 'foo', 'baz' ); 721 722 $q = new WP_User_Query( array( 723 'who' => 'authors', 724 'blog_id' => $b, 725 'meta_key' => 'foo', 726 'meta_value' => 'bar', 696 727 ) ); 697 728
Note: See TracChangeset
for help on using the changeset viewer.