How to get the currently logged in user's role in Drupal 7?

$GLOBALS['user']->roles;
 or 
global $user; 
$check = array_intersect(array('authenticated user', 'administrator'), array_values($user->roles)); 

if (empty($check) ? FALSE : TRUE) { 
	// is admin
} else {
 	// is not admin 
} 

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.