From 1d02d4bf27ccb0f8b8c5c33c22adb76b174208a3 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 16 Oct 2012 20:05:40 +0000 Subject: [PATCH] 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: https://develop.svn.wordpress.org/trunk@22248 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/capabilities.php | 10 +++++++++- wp-includes/user.php | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index b493eee0d7..b6a495c932 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -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; diff --git a/wp-includes/user.php b/wp-includes/user.php index b38fbb5e26..187a9b6b05 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -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 ); + } } }