how to check user group permission in my addon

arpitjain

Member
i have created a new permission with all user group permission through Permission Definitions

....i want to check for permission that i create ...in extended resource controller ..how it is possible...is there any function that will check for particular permission id..
 
First you will need to get the permissions for the user (XenForo_Visitor::getInstance()->toArray()["permissions"]), then use XenForo_Permissions::hasPermission(permissionArray, permissionGroup, permissionID) to check whether the user has permissions. Additionally, a shortcut XenForo_Visitor::getInstance()->hasPermission(permissionGroup, permissionID) is also available.

I highly recommend you to dig around XF's code to see it in action.
 
Here's an example from my Show Deleted add-on.

In this case I'm checking to see if the user has the permission to view soft deleted posts and threads.

PHP:
    // get permissions
     $permissions = XenForo_Visitor::getInstance()->getPermissions();
     
     // get viewDeleted permission
     $viewDeleted = XenForo_Permission::hasPermission($permissions, "forum", "viewDeleted");
     
     // if viewDeleted is false display no permission response
     if (!$viewDeleted)
     {
       throw $this->getNoPermissionResponseException();
     }
 
Back
Top Bottom