function user_load_by_mail

Same name and namespace in other branches
  1. 11.x core/modules/user/user.module \user_load_by_mail()
  2. 10 core/modules/user/user.module \user_load_by_mail()
  3. 9 core/modules/user/user.module \user_load_by_mail()
  4. 8.9.x core/modules/user/user.module \user_load_by_mail()
  5. 7.x modules/user/user.module \user_load_by_mail()

Fetches a user object by email address.

Parameters

string $mail: String with the account's email address.

Return value

\Drupal\user\UserInterface|false A fully-loaded $user object upon successful user load or FALSE if user cannot be loaded.

Deprecated

in drupal:11.4.0 and is removed from drupal:13.0.0. Use \Drupal::entityTypeManager()->getStorage('user')->loadByProperties() instead.

See also

https://www.drupal.org/node/3555936

File

core/modules/user/user.module, line 45

Code

function user_load_by_mail($mail) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use entityTypeManager()->getStorage("user")->loadByProperties() instead. See https://www.drupal.org/node/3555936', E_USER_DEPRECATED);
  $users = \Drupal::entityTypeManager()->getStorage('user')
    ->loadByProperties([
    'mail' => $mail,
  ]);
  return $users ? reset($users) : FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.