How to check user role without using current_user_can()

I am filtering the map_meta_cap() function, which is called from $user->has_cap (which is called from current_user_can()). I only want my filter to execute if the current user is an administrator, so I need a conditional in my filter that checks their role.

I can’t use current_user_can(), because that invokes my filter, causing an infinite loop.

Read More

Is there a reliable way to check whether someone is an administrator without using current_user_can() ?

Related posts

Leave a Reply

1 comment

  1. You could check the $current_user variable to determine the role.

    I believe it should be realiable after init(maybe even on init) for a logged in user, a guest visitor obviously won’t have any data associated with him or her yet(so it’ll be empty/unset).

    You can also call up get_currentuserinfo() to populate the $current_user var, but i’ve personally never found a need when calling $current_user after init(but i’m sure there may be cases when you need to call it, so it’s linked below for reference).

    http://codex.wordpress.org/Function_Reference/get_currentuserinfo