To check if a user has a specific role like the authenticated user, the following code could help.
global $user; if (in_array('authenticated user', $user->roles)) { // This user has 'authenticated user' role }
If you wanna check whether the user has any one of the multiple roles, use the following instead
global $user; $has_role = array_intersect(array('<role A>', '<role B>', '<role C>'), array_values($user->roles)); if (empty($has_role) ? FALSE : TRUE) { // This user has any one of the three roles }
Done =)
Reference: StackOverflow – How to get the currently logged in user’s role in Drupal 7?