Permissions
If you want to make the permissions for different actions of your plugin configurable by user role, you can register the available actions with the permissions extension.
Custom Panel areas
If your plugin registers a Panel area, it automatically gets an access.<areaId> permission. You do not need the permissions extension for that.
Kirby::plugin('my/todos', [
'areas' => [
'todos' => fn () => [ /* ... */ ]
]
]);
permissions:
access:
todos: false
Use the permissions extension only for actions inside your plugin (create, delete, publish …), not for access to the area itself.
PHP definition
Each available action needs to be set with the default permission value. The default value is used if the user's role does not specify the permissions for that action.
Kirby::plugin('my/permissionPlugin', [
'permissions' => [
'access' => true,
'create' => true,
'delete' => false
]
]);
All permissions of the Kirby core are set to true by default. Only use the default value false if you want to make sure that the action is enabled explicitly for the users who should have access to it.
Usage in the user blueprint
The permissions can now be set in the user blueprint for each role (just like the core permissions).
Your permissions are grouped under a category named after the plugin, with the slash replaced by a dot: my/permissionPlugin becomes my.permissionPlugin. Use exactly that key in the user blueprint.
title: Editor
permissions:
my.permissionPlugin:
*: false
access: true
Access from your plugin
You can then check the permissions for each action in your plugin:
$kirby->user()->role()->permissions()->for('my.permissionPlugin', 'access') // true
$kirby->user()->role()->permissions()->for('my.permissionPlugin', 'create') // false