Make WordPress Core

Changeset 21413


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.

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-activate.php

    r19593 r21413  
    7878            extract($result);
    7979            $url = get_blogaddress_by_id( (int) $blog_id);
    80             $user = new WP_User( (int) $user_id);
     80            $user = get_userdata( (int) $user_id);
    8181            ?>
    8282            <h2><?php _e('Your account is now active!'); ?></h2>
  • trunk/wp-admin/includes/ajax-actions.php

    r21203 r21413  
    10191019        $x->send();
    10201020    }
    1021     $user_object = new WP_User( $user_id );
     1021    $user_object = get_userdata( $user_id );
    10221022
    10231023    $wp_list_table = _get_list_table('WP_Users_List_Table');
  • trunk/wp-admin/includes/class-wp-users-list-table.php

    r21364 r21413  
    219219
    220220        if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
    221             $user_object = new WP_User( (int) $user_object );
     221            $user_object = get_userdata( (int) $user_object );
    222222        $user_object->filter = 'display';
    223223        $email = $user_object->user_email;
  • trunk/wp-admin/includes/deprecated.php

    r21353 r21413  
    250250    global $wpdb;
    251251
    252     $user = new WP_User( $user_id );
     252    if ( ! $user = get_userdata( $user_id ) )
     253        return array();
    253254    $post_type_obj = get_post_type_object($post_type);
    254255
  • trunk/wp-admin/includes/ms.php

    r21387 r21413  
    690690    $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
    691691
    692     $user = new WP_User( $user_id );
    693     if ( ! in_array( $user->user_login, $super_admins ) ) {
     692    $user = get_userdata( $user_id );
     693    if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
    694694        $super_admins[] = $user->user_login;
    695695        update_site_option( 'site_admins' , $super_admins );
     
    718718    $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
    719719
    720     $user = new WP_User( $user_id );
    721     if ( $user->user_email != get_site_option( 'admin_email' ) ) {
     720    $user = get_userdata( $user_id );
     721    if ( $user && $user->user_email != get_site_option( 'admin_email' ) ) {
    722722        if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
    723723            unset( $super_admins[$key] );
  • trunk/wp-admin/includes/upgrade.php

    r21333 r21413  
    321321 */
    322322function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
    323     $user = new WP_User($user_id);
     323    $user = new WP_User( $user_id );
    324324    $email = $user->user_email;
    325325    $name = $user->user_login;
  • trunk/wp-admin/includes/user.php

    r21364 r21413  
    199199 */
    200200function get_user_to_edit( $user_id ) {
    201     $user = new WP_User( $user_id );
     201    $user = get_userdata( $user_id );
    202202
    203203    $user->filter = 'edit';
  • trunk/wp-admin/network/site-users.php

    r21003 r21413  
    144144                        wp_die(__('Cheatin&#8217; uh?'));
    145145
    146                     $user = new WP_User( $user_id );
     146                    $user = get_userdata( $user_id );
    147147                    $user->set_role( $_REQUEST['new_role'] );
    148148                }
  • trunk/wp-admin/network/users.php

    r21003 r21413  
    3535    foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
    3636        if ( $val != '' && $val != '0' ) {
    37             $delete_user = new WP_User( $val );
     37            $delete_user = get_userdata( $val );
    3838
    3939            if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
     
    140140
    141141                            case 'spam':
    142                                 $user = new WP_User( $val );
    143                                 if ( in_array( $user->user_login, get_super_admins() ) )
     142                                $user = get_userdata( $val );
     143                                if ( is_super_admin( $user->ID ) )
    144144                                    wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
    145145
  • trunk/wp-admin/users.php

    r21003 r21413  
    112112            wp_die(__('Cheatin&#8217; uh?'));
    113113
    114         $user = new WP_User($id);
     114        $user = get_userdata( $id );
    115115        $user->set_role($_REQUEST['new_role']);
    116116    }
     
    202202    foreach ( $userids as $id ) {
    203203        $id = (int) $id;
    204         $user = new WP_User($id);
     204        $user = get_userdata( $id );
    205205        if ( $id == $current_user->ID ) {
    206206            echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
     
    303303    foreach ( $userids as $id ) {
    304304        $id = (int) $id;
    305         $user = new WP_User($id);
     305        $user = get_userdata( $id );
    306306        if ( $id == $current_user->ID && !is_super_admin() ) {
    307307            echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
  • trunk/wp-includes/capabilities.php

    r21377 r21413  
    12381238
    12391239    // Create new object to avoid stomping the global current_user.
    1240     $user = new WP_User( $current_user->ID) ;
     1240    $user = new WP_User( $current_user->ID );
    12411241
    12421242    // Set the blog id. @todo add blog id arg to WP_User constructor?
     
    12621262        return false;
    12631263
    1264     $author = new WP_User( $post->post_author );
    1265 
    1266     if ( empty( $author->ID ) )
     1264    $author = get_userdata( $post->post_author );
     1265
     1266    if ( ! $author )
    12671267        return false;
    12681268
     
    12841284function user_can( $user, $capability ) {
    12851285    if ( ! is_object( $user ) )
    1286         $user = new WP_User( $user );
     1286        $user = get_userdata( $user );
    12871287
    12881288    if ( ! $user || ! $user->exists() )
  • trunk/wp-includes/comment.php

    r21186 r21413  
    651651    do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );
    652652
    653     if ( isset($user_id) && $user_id) {
    654         $userdata = get_userdata($user_id);
    655         $user = new WP_User($user_id);
     653    if ( ! empty( $user_id ) ) {
     654        $user = get_userdata( $user_id );
    656655        $post_author = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", $comment_post_ID));
    657656    }
    658657
    659     if ( isset($userdata) && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {
     658    if ( $user && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {
    660659        // The author and the admins get respect.
    661660        $approved = 1;
  • trunk/wp-includes/link-template.php

    r21364 r21413  
    10721072        return '';
    10731073
    1074     $user = new WP_User( $user_id );
    1075 
    1076     if ( ! $user->exists() )
     1074    $user = get_userdata( $user_id );
     1075
     1076    if ( ! $user )
    10771077        return '';
    10781078
  • trunk/wp-includes/ms-functions.php

    r21387 r21413  
    184184    switch_to_blog($blog_id);
    185185
    186     $user = new WP_User($user_id);
    187 
    188     if ( ! $user->exists() ) {
     186    $user = get_userdata( $user_id );
     187
     188    if ( ! $user ) {
    189189        restore_current_blog();
    190190        return new WP_Error('user_does_not_exist', __('That user does not exist.'));
     
    247247
    248248    // wp_revoke_user($user_id);
    249     $user = new WP_User($user_id);
    250     if ( ! $user->exists() ) {
     249    $user = get_userdata( $user_id );
     250    if ( ! $user ) {
    251251        restore_current_blog();
    252252        return new WP_Error('user_does_not_exist', __('That user does not exist.'));
     
    10571057        return false;
    10581058
    1059     $user = new WP_User($user_id);
     1059    $user = get_userdata( $user_id );
    10601060
    10611061    $options_site_url = esc_url(network_admin_url('settings.php'));
     
    12341234
    12351235    $url = get_blogaddress_by_id($blog_id);
    1236     $user = new WP_User($user_id);
     1236    $user = get_userdata( $user_id );
    12371237
    12381238    $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
     
    12831283    $welcome_email = get_site_option( 'welcome_user_email' );
    12841284
    1285     $user = new WP_User($user_id);
     1285    $user = get_userdata( $user_id );
    12861286
    12871287    $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta);
     
    15091509function wpmu_log_new_registrations( $blog_id, $user_id ) {
    15101510    global $wpdb;
    1511     $user = new WP_User( (int) $user_id );
     1511    $user = get_userdata( (int) $user_id );
    15121512    $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) );
    15131513}
     
    17521752        $user_id = get_user_id_from_string( $username );
    17531753    }
    1754     $u = new WP_User( $user_id );
     1754    $u = get_userdata( $user_id );
    17551755
    17561756    return ( isset( $u->spam ) && $u->spam == 1 );
  • trunk/wp-includes/pluggable.php

    r21376 r21413  
    11991199 */
    12001200function wp_new_user_notification($user_id, $plaintext_pass = '') {
    1201     $user = new WP_User($user_id);
     1201    $user = get_userdata( $user_id );
    12021202
    12031203    $user_login = stripslashes($user->user_login);
  • 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.