Created
February 15, 2018 20:50
-
-
Save adrianspeyer/d9172e91dd2b8461b0a98113a6e3c41c to your computer and use it in GitHub Desktop.
Add to your theme hook to always have user 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
public function base_render_before($sender) { | |
if(!val('UserRoles', $sender->Data)) { | |
$user = val('User', Gdn::controller()); | |
if (!$user && Gdn::session()->isValid()) { | |
$user = Gdn::session()->User; | |
} | |
$userRoles = []; | |
if ($user) { | |
$userID = val('UserID', $user); | |
$userRolesData = Gdn::userModel()->getRoles($userID); | |
if ($userRolesData->numRows() > 0) { | |
$userRoles = array_column($userRolesData->resultArray(), 'Name'); | |
} | |
} | |
$sender->setData('UserRoles', $userRoles); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment