[wp-hackers] get_user_meta returning empty string

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


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



On Wed, Nov 24, 2010 at 12:10 PM, Muro, Matthew <mmuro at advance.ua.edu> wrote:
> Either way, the fix is to grab the global $table_prefix.
>
> Can you explain why get_userdata is better than get_user_meta?  I don't mind switching, but it would be helpful to know the difference.
>
> Matthew Muro
> Web Developer
> UA Office of Web Communications
>
>
>
> On Wed, Nov 24, 2010 at 7:35 PM, scribu <m...<http://groups.google.com/groups/unlock?_done=/group/wp-hackers/browse_thread/thread/90ad24814648dd47&msg=908f6daa02989e7e>@scribu.net> wrote:
>> On Wed, Nov 24, 2010 at 7:16 PM, Muro, Matthew <mm...<http://groups.google.com/groups/unlock?_done=/group/wp-hackers/browse_thread/thread/90ad24814648dd47&msg=908f6daa02989e7e>@advance.ua.edu>wrote:
>
>>> Never underestimate the power of posting.  The problem ended up being that
>>> someone using a different $table_prefix other than "wp_" wouldn't have the
>>> meta_key "wp_capabilities".
>
>>> Let me know if I'm jumping to conclusions here, but I'm able to reproduce
>>> the error.
>
>> That would only happen if you change the table prefix *after* WP is
>> installed.
>
>
> To clarify, the capability key is generated based on the table prefix. This
> allows users to have different capabilities on different sites in a
> MultiSite environment.
>
> Also, you should probably be using get_userdata() instead.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list