ExpressionEngine Docs

Permission Service

Simple Example

The permission service checks for member authorization as indicated in the session userdata. Superadmins automatically have permission.

To check for exactly 1 permission:

if (ee('Permission')->has('can_edit_all_comments'))
{
  $this->show_form();
}

To check for the existence of at least one permission among a list of permissions:

if (ee('Permission')->hasAny('can_create_template_partials', 'can_edit_template_partials', 'can_delete_template_partials'))
{
  $this->show_header();
}

To check for the existence of all listed permissions:

$can_delete = ee('Permission')->hasAll('can_delete_all_comments', 'can_delete_own_comments')

Permission Service Methods

class ExpressionEngine\Service\Permission\Permission

has($permission)

Checks a session object for a single permission

Parameter Type Description
$permission String A single permission name
Returns Boolean TRUE if allowed FALSE if not

hasAny($permission)

Checks a session object for any matches against a collection of permissions, from one on up.

Parameter Type Description
$permission Mixed Any number of permission names
Returns Boolean TRUE if allowed FALSE if not

hasAll($permission)

Checks a session object matches all permissions in a collection of permissions, from one on up.

Parameter Type Description
$permission Mixed Any number of permission names
Returns Boolean TRUE if allowed FALSE if not

isSuperAdmin()

Returns true if logged in member is Super Admins, false otherwise

hasRole($role)

Checks whether member has given role

Parameter Type Description
$role Mixed ID or name of member role
Returns Boolean TRUE if user has role FALSE if not

hasAnyRole($roles)

Checks whether user has any of given roles, supplied as array of IDs or names.

Parameter Type Description
$roles Array Array of IDs or names of member roles
Returns Boolean TRUE if user has role FALSE if not

rolesThatHave($permission, $site_id = NULL, $fuzzy = false)

Checks a session object for any matches against a collection of permissions, from one on up.

Parameter Type Description
$permission String Permission name, or start of permission name
$site_id Int Site ID, defaults to current site
$fuzzy Boolean TRUE if first parameter is start of permission name
Returns Array Array of Role IDs

Available Permissions

The following are permission names available for validating a user’s permissions using the Permission Service methods.

The following are available for each channel, X being the channel ID.

Template editing permissions are being set for each template group, X being template group ID.