I don't think there's an API function to do exactly that, but a single database query would get you that information:
// Query the database
$args = array(':email' => $email_address);
$lang = db_query('SELECT language FROM {users} WHERE mail = :email', $args)->fetchField();
// If there's no language string use LANGUAGE_UNDEFINED instead.
// This is also a fallback method to use the default language
// if the user is not found in the database.
if (!$lang || empty($lang)) {
$lang = LANGUAGE_UNDEFINED; // Or whatever your default language is
}
If you need the user object itself for whatever reason, you can use a slight variation on the above:
$args = array(':email' => $email_address);
$uid = db_query('SELECT uid FROM {users} WHERE mail = :email', $args)->fetchField();
if ($uid) {
$account = user_load($uid);
$lang = $account->language;
}
You could also take advantage of the $conditions
parameter of user_load_multiple()
, but this method has been deprecated so it might not be the best idea to use it:
$users = user_load_multiple(array(), array('mail' => $email_address));
if (!empty($users)) {
$account = array_shift($users);
$lang = $account->language;
}
Last but not least, you could use an EntityFieldQuery
, although this would probably be overkill for this particular task. It is a useful thing to know though:
$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'user')
->propertyCondition('mail', $email_address);
$results = $query->execute();
if (isset($results['user'])) {
$users = user_load_multiple(array_keys($results['user']));
if (!empty($users)) {
$account = array_shift($users);
$lang = $account->language;
}
}