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

Returns true 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 (boolean)

There is also $user->permission($event, $args = []) that also returns an error message if the user has no permission.
If you want to check if the user has no permission, use $user->cannot($event, $args = []), which otherwise does the same.


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

if($user->can('myplugin.permission', ['arg1', 'arg2'])) {
  // user has permission
} else {
  // user has no permission

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