[wp-hackers] get_user_meta returning empty string

Muro, Matthew mmuro at advance.ua.edu
Thu Nov 25 18:05:58 UTC 2010


After examining the WP_User object, I have a small correction to Otto's code from earlier.

It should be $user->roles, not $user->role.

$user = new WP_User($id);
var_dump($user->roles);

Matthew Muro

>Not at all, get_user_meta isn't going anywhere. We rarely deprecate
>functions (100 of 4,000 over 7 years), and even when we do so, they
>typically remain functional.
>
>However, you're using get_user_meta to fetch internals. What you're doing
>isn't much different from a direct SQL call. There's a reason why there's
>another layer of abstraction for the roles/capabilities system (as well as
>many other APIs) -- so you can use it.
>
>We're very likely to change how roles and capabilities are stored in the
>database in a future release, perhaps 3.2 or 3.3. If you continue to use
>WP_Role, WP_Roles, WP_User, and related (proper) functions, nothing will
>break. If you go straight to the database, I pretty much guarantee your code
>will break.
>
>For what it's worth, some sites do not store role definitions in the
>database. One more reason to use the API.


More information about the wp-hackers mailing list