// Check to see if $user has the administrator role. if (in_array('administrator', array_values($user->roles))) { // Do something. } ?>
<?php /** * Check to see if a user has been assigned a certain role. * * @param $role * The name of the role you're trying to find. * @param $user * The user object for the user you're checking; defaults to the current user. * @return * TRUE if the user object has the role, FALSE if it does not. */ function user_has_role($role, $user = NULL) { if ($user == NULL) { global $user; }
if (is_array($user->roles) && in_array($role, array_values($user->roles))) { return TRUE; }