Documenation

Permission

/_plugins/permission.php

Permissions can be used to grant specific users access to pages or functionality. Permissions can be managed through the administrative interface linked from the Dashboard.

With the permissions plugin installed other plugins can create custom permissions, typically on installation using the install hook.

Example
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
if ( !isset($model) ) die('Direct access to this file is not allowed');

switch ( 
$hook )
{
    case 
'info':
        
$info = array(
            
'name'       => 'secret',
            
'version'    => '1.0.0',
            
'compatible' => array('from' => '1.2.0''to' => '1.2.*'),
            
'hooks'      => array('install' => 1'remove' => 1)
            );

        break;
    case 
'install':
        if ( !empty(
$model->node->ready) )
        {
            
$model->perm->create('Secrets''secret access''Access to secret');
        }

        break;
    case 
'remove':
        if ( !empty(
$model->node->ready) )
        {
            
$model->perm->delete('secret access');
        }

        break;
}
?>

To see if the current user has permission to access secret:

1
2
3
4
5
6
<?php
if ( $model->perm->check('secret access') )
{
    
// User has access to secret
}
?>

Class

$model->perm

Public functions

  • $model->perm->check ( string $name )
    Checks if the current user has permission.
  • $model->perm->create ( string $group, string $name, string $description )
    Creates a new permission.
  • $model->perm->delete ( string $name )
    Deletes a permission

Constants

  • perm::roleOwnerId
    User id of the default owner (the first user).
  • perm::yes
    The user has permission.
  • perm::no
    The user has no permission (default).
  • perm::never
    The user has no permission, can not be overridden.

See also