Create bulk users with optional email in Kirby 4

Following the guide: $users->create() | Kirby CMS

In my case emails are optional, so email is often “”. In Kirby 2 this worked without any problems.

In Kirby 4 i always get an exception when I create a user, even when I try to exclude the “email” property like so:

if(filter_var($file->arr["Student"]["Email"], FILTER_VALIDATE_EMAIL)){

  $user = $kirby->users()->create(array(
    'name' => $file->arr["Student"]["Username"],
    'email' => $file->arr["Student"]["Email"],
    'password' => $passwort,
    'language'  => 'de',
    'role' => "client",
    'content' => [
       'firstName' => $file->arr["Student"]["Vorname"],
        'lastName' => $file->arr["Student"]["Nachname"],
        'jahrgang' => $file->arr["Student"]["Jahrgang"],
] ));

}else {
  $user = $kirby->users()->create(array(
    'name' => $file->arr["Student"]["Username"],
    'password' => $passwort,
    'language'  => 'de',
    'role' => "client",
     'content' => [
          'firstName' => $file->arr["Student"]["Vorname"],
           'lastName' => $file->arr["Student"]["Nachname"],
           'jahrgang' => $file->arr["Student"]["Jahrgang"],
]
));
}

Email seems strictly required. Is there a solution for this?

In addition, the login seems to work only with the e-mail address as username and no longer with the account name? - That was different with Kirby 2 - or can the behaviour be configured somewhere?

No, the behavior cannot be configured. That change from username to email was introduced in Kirby 3 by request of the community.

It could work with a custom user model, but I guess you would have to change the login form as well.

Okay, thanks, i stick with the default. Then email addresses are a mandatory field from now on.