diff --git src/wp-includes/user.php src/wp-includes/user.php
index e602a3e..f1a09b0 100644
|
|
|
class WP_User_Query {
|
| 555 | 555 | * of fields. Accepts 'ID', 'display_name', 'login', 'nicename', 'email', |
| 556 | 556 | * 'url', 'registered'. Use 'all' for all fields and 'all_with_meta' to |
| 557 | 557 | * include meta fields. Default 'all'. |
| 558 | | * @type string $who Type of users to query. Accepts 'authors'. Default empty (all users). |
| | 558 | * @type string $who Type of users to query. Accepts 'authors', 'public_author'. Default empty (all users). |
| 559 | 559 | * } |
| 560 | 560 | */ |
| 561 | 561 | public function prepare_query( $query = array() ) { |
| … |
… |
class WP_User_Query {
|
| 631 | 631 | $blog_id = absint( $qv['blog_id'] ); |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | | if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) { |
| 635 | | $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level'; |
| 636 | | $qv['meta_value'] = 0; |
| 637 | | $qv['meta_compare'] = '!='; |
| | 634 | if ( isset( $qv['who'] ) && $blog_id ) { |
| | 635 | |
| | 636 | if ( 'authors' == $qv['who'] ) { |
| | 637 | $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level'; |
| | 638 | $qv['meta_value'] = 0; |
| | 639 | $qv['meta_compare'] = '!='; |
| | 640 | } else if ( 'public_authors' == $qv['who'] ) { |
| | 641 | |
| | 642 | $this->query_from .= " JOIN $wpdb->posts ON $wpdb->posts.post_author = $wpdb->users.ID"; |
| | 643 | |
| | 644 | $post_types = get_post_types( array( 'public' => true ) ); |
| | 645 | $this->query_where .= " AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type IN ( '" . join( "', '", $post_types ) . "' )"; |
| | 646 | |
| | 647 | } |
| | 648 | |
| 638 | 649 | $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query |
| 639 | 650 | } |
| 640 | 651 | |
diff --git tests/phpunit/tests/user/query.php tests/phpunit/tests/user/query.php
index 9abf99d..dbd378a 100644
|
|
|
class Tests_User_Query extends WP_UnitTestCase {
|
| 686 | 686 | $this->assertContains( $users[1], $found ); |
| 687 | 687 | $this->assertNotContains( $users[2], $found ); |
| 688 | 688 | } |
| | 689 | |
| | 690 | public function test_who_public_authors() { |
| | 691 | |
| | 692 | $users = $this->factory->user->create_many( 3 ); |
| | 693 | |
| | 694 | $this->factory->post->create( array( 'post_author' => $users[0], 'post_status' => 'publish', 'post_type' => 'post' ) ); |
| | 695 | $this->factory->post->create( array( 'post_author' => $users[1], 'post_status' => 'publish', 'post_type' => 'post' ) ); |
| | 696 | |
| | 697 | $q = new WP_User_Query( array( |
| | 698 | 'who' => 'public_authors', |
| | 699 | ) ); |
| | 700 | |
| | 701 | $found = wp_list_pluck( $q->get_results(), 'ID' ); |
| | 702 | |
| | 703 | $this->assertEquals( 2, $q->get_total() ); |
| | 704 | |
| | 705 | $this->assertContains( $users[0], $found ); |
| | 706 | $this->assertContains( $users[1], $found ); |
| | 707 | } |
| 689 | 708 | } |