Skip to content

Kirby 4.5.0

$users->create()

$users->create(array $data): Kirby\Cms\User

Parameters

Name Type Default
$data * array

Return type

Kirby\Cms\User

Parent class

Kirby\Cms\Users

Example

try {

  $user = $kirby->users()->create([
    'name'      => 'john',
    'email'     => 'john@doe.com',
    'password'  => 'secretpasswordwillbeencrypted',
    'language'  => 'en',
    'role'      => 'editor',
    'content'   => [
      'birthdate' => '1989-01-29'
    ]
  ]);

  echo 'The user "' . $user->name() . '" has been created';

} catch(Exception $e) {

  echo 'The user could not be created';
  // optional error message: $e->getMessage();

}