Last active
May 23, 2021 18:41
-
-
Save frankyonnetti/5944740 to your computer and use it in GitHub Desktop.
#drupal checked if logged in / role
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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