Skip to content

Kirby 5.0.4

$users->create()

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

Parameters

Name Type Default
$datarequired array no default value

Return type

Kirby\Cms\User

This method modifies the existing $users object it is applied to and returns it again.

Parent class

Kirby\Cms\Users

Examples

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();

}