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

Permissions

ManagerJosh

Well-known member
#1
Is there developer documentation or tutorials that explains how to leverage the existing permission system inside XF and build upon it in order to create/add/manage permissions for a potential addon?
 

Jake B.

Well-known member
#2
Just use the interface for creating new permissions, and use something along the lines of:

Code:
$visitor = XenForo_Visitor::getInstance();
if ($visitor->hasPermission('permission_group_id', 'permission_id')
{
    // Do something if they have permission
}
That will work in most cases, otherwise you'll want to use
Code:
$userModel = $this->getModelFromCache('XenForo_Model_User');
$user = $userModel->getUserById($userId);
$user['permission'] = @unserialize($user['global_permission_cache']);
if (XenForo_Permission::hasPermission($user['permissions'], 'permission_group_id', 'permission_id'))
{
    // Do something if they have permission
}
 

ManagerJosh

Well-known member
#3
Just use the interface for creating new permissions, and use something along the lines of:

Code:
$visitor = XenForo_Visitor::getInstance();
if ($visitor->hasPermission('permission_group_id', 'permission_id')
{
    // Do something if they have permission
}
That will work in most cases, otherwise you'll want to use
Code:
$userModel = $this->getModelFromCache('XenForo_Model_User');
$user = $userModel->getUserById($userId);
$user['permission'] = @unserialize($user['global_permission_cache']);
if (XenForo_Permission::hasPermission($user['permissions'], 'permission_group_id', 'permission_id'))
{
    // Do something if they have permission
}
What about adding our own category and permission sets inside the permission area in the AdminCP?