Return WP_User objects when querying 'all' fields with WP_User_Query.

Allow passing stdClass or WP_User to the WP_User constructor.

fixes #22057


git-svn-id: http://core.svn.wordpress.org/trunk@22248 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2012-10-16 20:05:40 +00:00
parent 74cea87b2c
commit f9ddde8da6
2 changed files with 13 additions and 1 deletions

View File

@ -459,7 +459,7 @@ class WP_User {
* @since 2.0.0
* @access public
*
* @param int|string $id User's ID
* @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB.
* @param string $name Optional. User's username
* @param int $blog_id Optional Blog ID, defaults to current blog.
* @return WP_User
@ -477,6 +477,14 @@ class WP_User {
);
}
if ( is_a( $id, 'WP_User' ) ) {
$this->init( $id->data, $blog_id );
return;
} elseif ( is_object( $id ) ) {
$this->init( $id, $blog_id );
return;
}
if ( ! empty( $id ) && ! is_numeric( $id ) ) {
$name = $id;
$id = 0;

View File

@ -559,6 +559,10 @@ class WP_User_Query {
$r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] );
$this->results = $r;
} elseif ( 'all' == $qv['fields'] ) {
foreach ( $this->results as $key => $user ) {
$this->results[ $key ] = new WP_User( $user );
}
}
}