Make WordPress Core


Ignore:
Timestamp:
08/03/2012 01:06:05 AM (12 years ago)
Author:
nacin
Message:

Move most instances of new WP_User to get_userdata(). see #21120.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r21374 r21413  
    8585    }
    8686
    87     $userdata = get_user_by('login', $username);
    88 
    89     if ( !$userdata )
     87    $user = get_user_by('login', $username);
     88
     89    if ( !$user )
    9090        return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), wp_lostpassword_url()));
    9191
    9292    if ( is_multisite() ) {
    9393        // Is user marked as spam?
    94         if ( 1 == $userdata->spam)
     94        if ( 1 == $user->spam)
    9595            return new WP_Error('invalid_username', __('<strong>ERROR</strong>: Your account has been marked as a spammer.'));
    9696
    9797        // Is a user's blog marked as spam?
    98         if ( !is_super_admin( $userdata->ID ) && isset($userdata->primary_blog) ) {
    99             $details = get_blog_details( $userdata->primary_blog );
     98        if ( !is_super_admin( $user->ID ) && isset($user->primary_blog) ) {
     99            $details = get_blog_details( $user->primary_blog );
    100100            if ( is_object( $details ) && $details->spam == 1 )
    101101                return new WP_Error('blog_suspended', __('Site Suspended.'));
     
    103103    }
    104104
    105     $userdata = apply_filters('wp_authenticate_user', $userdata, $password);
    106     if ( is_wp_error($userdata) )
    107         return $userdata;
    108 
    109     if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) )
     105    $user = apply_filters('wp_authenticate_user', $user, $password);
     106    if ( is_wp_error($user) )
     107        return $user;
     108
     109    if ( !wp_check_password($password, $user->user_pass, $user->ID) )
    110110        return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s" title="Password Lost and Found">Lost your password</a>?' ),
    111111        $username, wp_lostpassword_url() ) );
    112112
    113     $user =  new WP_User($userdata->ID);
    114113    return $user;
    115114}
     
    256255
    257256    if ( empty( $user ) )
    258         $user = wp_get_current_user();
    259     else
    260         $user = new WP_User( $user );
    261 
    262     if ( ! $user->exists() )
     257        $user = get_current_user_id();
     258
     259    if ( ! $user = get_userdata( $user ) )
    263260        return false;
    264261
     
    929926
    930927    if ( '' == $for_user_id )
    931         $user = wp_get_current_user();
    932     else
    933         $user = new WP_User($for_user_id);
    934 
    935     $userdata   = null;
    936     $user_ID    = (int) $user->ID;
    937     $user_level = (int) isset($user->user_level) ? $user->user_level : 0;
    938 
    939     if ( ! $user->exists() ) {
     928        $for_user_id = get_current_user_id();
     929    $user = get_userdata( $for_user_id );
     930
     931    if ( ! $user ) {
     932        $user_ID = 0;
     933        $user_level = 0;
     934        $userdata = null;
    940935        $user_login = $user_email = $user_url = $user_identity = '';
    941936        return;
    942937    }
    943938
     939    $user_ID    = (int) $user->ID;
     940    $user_level = (int) $user->user_level;
    944941    $userdata   = $user;
    945942    $user_login = $user->user_login;
Note: See TracChangeset for help on using the changeset viewer.