$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 $user->can($event, $args = []), which otherwise does the same.


$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

Is something missing or incorrect? Edit this page on Github…