/**
  * Retrieve user info by email.
  *
  * @since 2.5
  *
  * @param string $email User's email address
  * @return bool|object False on failure, User DB row object
  */
 function get_user_by_email($email)
 {
     global $wpdb;
     $user_id = wp_cache_get($email, 'useremail');
     $user = false;
     if (false !== $user_id) {
         $user = wp_cache_get($user_id, 'users');
     }
     if (false !== $user) {
         promote_if_site_admin($user);
         return $user;
     }
     if (!($user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE user_email = %s", $email)))) {
         return false;
     }
     _fill_user($user);
     return $user;
 }
Beispiel #2
0
function _fill_user(&$user)
{
    global $wpdb;
    $show = $wpdb->hide_errors();
    $metavalues = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->usermeta} WHERE user_id = %d", $user->ID));
    $wpdb->show_errors($show);
    if ($metavalues) {
        foreach ($metavalues as $meta) {
            $value = maybe_unserialize($meta->meta_value);
            $user->{$meta->meta_key} = $value;
        }
    }
    $level = $wpdb->prefix . 'user_level';
    if (isset($user->{$level})) {
        $user->user_level = $user->{$level};
    }
    // For backwards compat.
    if (isset($user->first_name)) {
        $user->user_firstname = $user->first_name;
    }
    if (isset($user->last_name)) {
        $user->user_lastname = $user->last_name;
    }
    if (isset($user->description)) {
        $user->user_description = $user->description;
    }
    promote_if_site_admin($user);
    wp_cache_add($user->ID, $user, 'users');
    wp_cache_add($user->user_login, $user->ID, 'userlogins');
    wp_cache_add($user->user_email, $user->ID, 'useremail');
}