Make WordPress Core

Changeset 32001


Ignore:
Timestamp:
04/03/2015 02:13:19 PM (10 years ago)
Author:
boonebgorges
Message:

WP_User_Query: When querying users with 'fields=all', ensure that caps and roles are filled for the current site.

See [15566] for a parallel fix for 'fields=all_with_meta'.

Fixes #31878.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r31963 r32001  
    858858        } elseif ( 'all' == $qv['fields'] ) {
    859859            foreach ( $this->results as $key => $user ) {
    860                 $this->results[ $key ] = new WP_User( $user );
     860                $this->results[ $key ] = new WP_User( $user, '', $qv['blog_id'] );
    861861            }
    862862        }
  • trunk/tests/phpunit/tests/user/query.php

    r32000 r32001  
    600600        $this->assertSame( array( 'author' => true ), $user->caps );
    601601    }
     602
     603    /**
     604     * @ticket 31878
     605     */
     606    public function test_roles_and_caps_should_be_populated_for_explicit_value_of_different_blog_id_on_ms_when_fields_all() {
     607        if ( ! is_multisite() ) {
     608            $this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
     609        }
     610
     611        $b = $this->factory->blog->create();
     612        $u = $this->factory->user->create();
     613        add_user_to_blog( $b, $u, 'author' );
     614
     615        $query = new WP_User_Query( array(
     616            'fields' => 'all',
     617            'include' => $u,
     618            'blog_id' => $b,
     619        ) );
     620
     621        $found = $query->get_results();
     622
     623        $this->assertNotEmpty( $found );
     624        $user = reset( $found );
     625        $this->assertSame( array( 'author' ), $user->roles );
     626        $this->assertSame( array( 'author' => true ), $user->caps );
     627    }
    602628}
Note: See TracChangeset for help on using the changeset viewer.