$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 (sheet: user/permission) that also returns an error message if the user has no permission.
If you want to check if the user has no permission, use (sheet: user/cannot), which otherwise does the same.

Example

$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
}