Add-On Permissions

Daniel 'RTRD'

Well-known member
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 */
        }
 
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')).
 
So something like this?:
PHP:
if ($visitor->hasPermission('group', 'permissionName')
{
    /* User does have permission */
}
else
{
    /* User does NOT have permission */
}
 
Top Bottom