Provide either an integer to check a single permission level or an array to check multiple levels.
2
$id = null
int
No
Specify the user id of the user whose permissions you want to check. Defaults to logged in user.
3
$masterCheck = true
bool
No
By default a user whose id is in the master account array is automatically returned as true. Specifying false here does an actual check to make sure the user has the proper permission set explicitly.
Returns
Data Type
Description of Returned Data
bool
Returns true or false denoting whether the user has a given permission.
Example
hasPerm([2,3,4])
Further Documentation:
This is the preferred way to check a permission level. If the user is in the $master_account variable set in init.php, this will always return true. In most places in the UserSpice code the first argument is looking for an array of permission levels to check.
As of version 5.0.5, if you only want to pass one permission level, you don't have to put it in [ ] . In other words, you can simply call hasPerm(2). If no second argument is passed, it will assume you are talking about the logged in user. However most places in the UserSpice code explicitly pass in $user->data()->id anyway.
$check = hasPerm([1,2]);
will return true if the logged in user has EITHER permission level 1 or 2.
$check = hasPerm(2);
will return true if the logged in user has permission level 2. PLEASE NOTE: It is better to pass an array in [] even if you are only using 1 permission level as this is a new feature only available in 5.0.5 or later.
$check = hasPerm([1,2],234);
will return true if the logged in user #234 has EITHER permission level 1 or 2.