Skip to content

Instantly share code, notes, and snippets.

@frankyonnetti
Last active May 23, 2021 18:41
Show Gist options
  • Save frankyonnetti/5944740 to your computer and use it in GitHub Desktop.
Save frankyonnetti/5944740 to your computer and use it in GitHub Desktop.
#drupal checked if logged in / role
<?php
global $user;
$has_role = array_intersect(array('administrator', 'Other admin', 'Client admin'), array_values($user->roles));
if (empty($has_role) ? FALSE : TRUE) {
// This user has any one of the three roles
}
?>
<?php if ($logged_in): ?>
<strong>Do something...</strong>
<?php endif; ?>
<?php if (!$logged_in): ?>
<strong>Do something else...</strong>
<?php endif; ?>
<?php
global $user;
// Check to see if $user has the administrator role.
if (in_array('administrator', array_values($user->roles))) {
// Do something.
}
// Check for multpile $users
if (in_array('administrator', array_values($user->roles)) && in_array('OtherAdmin', array_values($user->roles))) {
// Do something.
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment