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. git-svn-id: https://develop.svn.wordpress.org/trunk@32001 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
86f074ffde
commit
468da41811
@ -857,7 +857,7 @@ class WP_User_Query {
|
||||
$this->results = $r;
|
||||
} elseif ( 'all' == $qv['fields'] ) {
|
||||
foreach ( $this->results as $key => $user ) {
|
||||
$this->results[ $key ] = new WP_User( $user );
|
||||
$this->results[ $key ] = new WP_User( $user, '', $qv['blog_id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -599,4 +599,30 @@ class Tests_User_Query extends WP_UnitTestCase {
|
||||
$this->assertSame( array( 'author' ), $user->roles );
|
||||
$this->assertSame( array( 'author' => true ), $user->caps );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31878
|
||||
*/
|
||||
public function test_roles_and_caps_should_be_populated_for_explicit_value_of_different_blog_id_on_ms_when_fields_all() {
|
||||
if ( ! is_multisite() ) {
|
||||
$this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
|
||||
}
|
||||
|
||||
$b = $this->factory->blog->create();
|
||||
$u = $this->factory->user->create();
|
||||
add_user_to_blog( $b, $u, 'author' );
|
||||
|
||||
$query = new WP_User_Query( array(
|
||||
'fields' => 'all',
|
||||
'include' => $u,
|
||||
'blog_id' => $b,
|
||||
) );
|
||||
|
||||
$found = $query->get_results();
|
||||
|
||||
$this->assertNotEmpty( $found );
|
||||
$user = reset( $found );
|
||||
$this->assertSame( array( 'author' ), $user->roles );
|
||||
$this->assertSame( array( 'author' => true ), $user->caps );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user