PermissionFlags module
Module name: permissionflags
You have to enable this module in site/_modules.php file to use it.
This module creates permission flags to authenticated users according to an associative array of tag names and descriptions. The flags are editable within the user add/edit page. The flags will always loaded and located in $user object.
Methods of File object
- permission_hasflag($flag,$u = null) - Check if the flag exist of the current user
- The
$flagparameter specifies the flag name to check. - If you specify the
$uparameter the function check the this parameter passed user object instead of the current user.
- The
Sample to define tags in _settings.php
...
global $user_permission_flags;
$user_permission_flags = [
'perm_createsome' => 'Permission to create something',
'perm_editsome' => 'Permission to edit something',
'perm_createother' => 'Permission to create other things',
'perm_editother' => 'Permission to edit other things',
];
...
Note: Because changing the flags may cause sql modifications in the database, you have to check sqlchema page
after every $user_permission_flags modification.
Use the flag in php codes
print "Hello ";
if(permission_hasflag('perm_editsome'))
{
print "you can ";
}
else
{
print "you cannot ";
}
print "edit something";