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

Add-On Permissions

Daniel 'RTRD'

Well-known member
#1
Is there a easy way to check if the user has permissions to view the specific content?

Is this correct?
PHP:
        if ($hasPermission)
        {
            /* User does have permission */
        }
        else
        {
            /* User does NOT have permission */
        }
 

Onimua

Well-known member
#2
It depends on how you want to tell the user. Usually it's done by:
PHP:
if (!$this->_getItemModel()->canSeeItem($item, $errorPhraseKey))
{
    throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
}
You skip the "else" portion if they can view it and just proceed with the rest of your code.

The check can be done with the visitor model ($visitor->hasPermission('group', 'permissionName') or through the permission class (XenForo_Permission::hasPermission($viewingUser['permissions'], 'group', 'permissionName')).
 

Daniel 'RTRD'

Well-known member
#3
So something like this?:
PHP:
if ($visitor->hasPermission('group', 'permissionName')
{
    /* User does have permission */
}
else
{
    /* User does NOT have permission */
}