$user->permission($event, $args = \[])

Checks if the user has permission for the specified event

  • since: Kirby 2.4.0
  • $event (Event/string)
    Event object or a string with the event name
  • $args (mixed)
    Additional arguments for the permission callbacks
  • return (Obj)
    Object with status() and message() methods

If you don't need the error message, use (sheet: user/can), which otherwise does the same.

Example

$user = site()->user();
if(!$user) throw new Exception('No user is logged in.');

$result = $user->permission('myplugin.permission', ['arg1', 'arg2']);
if($result->status()) {
  // user has permission
} else if($message = $result->message()) {
  // user has no permission and $message contains why
} else {
  // user has no permission but the role doesn't want to tell why
}