Check for usergroup?

overifist

Member
So how do I check to see if a person is in a group for accesing a page?

Like this:
Code:
$visitor = XenForo_Visitor::getInstance();
        if (!$visitor['is_moderator'])
        {
            throw $this->getNoPermissionResponseException();
        }
 
If you have a usergroup permission for that page you can use this:

PHP:
// Check user group permissions
if (!$visitor->hasPermission('Permission_Group', 'Permission_Name'))
{
    throw $this->getNoPermissionResponseException();
}

Otherwise you can check his usergroups like this:

Rich (BB code):
if (!$visitor->isMemberOf(4))
{
    throw $this->getNoPermissionResponseException();
}

Change number 4 to the allowed usergroup, if you want to add more usergroups replace the number 4 with array(4,3) you can add more groups by adding their group_id separating them by comma.
 
Top Bottom