Skip to content

Kirby 3.9.8

user.create:before

/site/config/config.php
return [
    'hooks' => [
        'user.create:before' => function (Kirby\Cms\User $user, array $input) {
            // your code goes here
        }
    ]
]

Parameters

Parameter Type
$user Kirby\Cms\User
$input array

Example

Prevent users with a specific role from creating new users with the same role:

<?php
return [
  'hooks' => [
    'user.create:before' => function (Kirby\Cms\User $user, array $input) {
      if ($user->role()->name() === 'editor' && kirby()->user()->role()->name() === 'editor') {
        throw new ErrorException('Sorry! You can only create users with the "client" role');
      }
    }
  ]
];

The $user parameter refers to the newly created Kirby\Cms\User object (not the currently logged-in user, which we get via kirby()->user()). The $input array contains the form data (name, email, passsword, language, role, model).