Methods of Checking User Permissions (Not Visitor)

James

Well-known member
What are the possible methods of checking for the currently logged in user's permissions? I'm trying to do a quick permission check in XenForo_Template_Helper_Core and struggling.
 
There are two ways...

XenForo_Permission::hasPermission($viewingUser['permissions'], 'PermissionGroup', 'PermissionId')
Code:
$viewingUser = null;
$this->standardizeViewingUserReference($viewingUser);

$perms['custom'] = (XenForo_Permission::hasPermission($viewingUser['permissions'], 'EWRporta', 'canCustom') ? true : false);

Or... you can do... (its not the "correct" way)
Code:
$visitor = XenForo_Visitor::getInstance();
$perms['custom'] = ($visitor['permissions']['EWRporta']['canCustom'] ? true : false);

The second method can even be used in templates!
(this may not be the correct way, but I have not run into any issues yet)
Code:
<xen:if is="$visitor.permissions.EWRporta.canCustom">
 
I managed to do this in the end by creating a user model and joining the permissions to the getUserById() function.
 
Top Bottom