[wp-hackers] get_user_meta returning empty string

Otto otto at ottodestruct.com
Wed Nov 24 18:56:18 UTC 2010


Oh, and BTW, the global $current_user is already an instance of the
WP_User, for the current user. So if you're talking about the current
user, then you can either just use that global directly, or do this if
you don't like using globals (I don't):

$user = wp_get_current_user();

-Otto

On Wed, Nov 24, 2010 at 12:52 PM, Otto <otto at ottodestruct.com> wrote:
> Actually, if you know the user ID, you'd be better off just using the
> WP_User object.
>
> $user = new WP_User($id);
>
> That will retrieve the properties of the user and create an object
> with it. However, it also goes and fetches their capabilities for the
> current blog as well. You can then use the functionality of the user
> object to check for specific capabilities. For example:
>
> if ($user->has_cap('edit_users')) ...
>
> If you just want to see all that user's capabilities, then you can
> look at the allcaps array:
>
> var_dump($user->allcaps);
>
> Simple. Works.
>
> -Otto


More information about the wp-hackers mailing list