[wp-hackers] User Roles
Andy Staines
andy at yellowswordfish.com
Mon Mar 19 16:59:22 GMT 2007
Peter Westwood wrote:
> On Mon, March 19, 2007 4:31 pm, Andy Staines wrote:
>
>> Peter Westwood wrote:
>>
>>> On Mon, March 19, 2007 4:01 pm, Andy Staines wrote:
>>>
>>>
>>>> So - is there an improvement on using wp_get_current_user() ?
>>>>
>>>>
>>> Yes.
>>>
>>> >From memory - current_user_can() should provide the functionality you
>>> want.
>>>
>>> current_user_can() calls has_cap() on the User object which has the
>>> following comment: /has_cap(capability_or_role_name)
>>> (http://trac.wordpress.org/browser/trunk/wp-includes/capabilities.php#L258)
>>>
>>> Therefore you should be able to do current_user_can("Administrator");
>>>
>>> westi
>>>
>>>
>> Thanks - but for that don't you need to either already know the role and
>> be interested in a specific capability? I just wish to determine the
>> current users 'role(s)' in the first place, in the simplest most
>> efficient way possible...
>> Andy
>>
>
> OK.
>
> ----
> foreach ($wp_roles->get_names() as $rolename => $roledescription)
> {
> if (current_user_can($rolename)) {
> $usersroles[] = $rolename;
> }
> }
> print_r($usersroles);
> ----
>
> Gives you the role(s) that apply to the current user.
>
> westi
>
Ah! Gotcha. Thanks Peter - I'll have a play with that....
--
yellow swordfish ANDY STAINES
email | andy at yellowswordfish.com <mailto:andy at yellowswordfish.com>
www | www.yellowswordfish.com
More information about the wp-hackers
mailing list