1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Methods of Checking User Permissions (Not Visitor)

Discussion in 'XenForo Development Discussions' started by James, Jul 21, 2011.

  1. James

    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.
     
  2. Jaxel

    Jaxel Well-Known Member

    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">
     
  3. James

    James Well-Known Member

    I managed to do this in the end by creating a user model and joining the permissions to the getUserById() function.
     

Share This Page