Make WordPress Core

Ticket #20372: 20372.4.diff

File 20372.4.diff, 1.9 KB (added by ryan, 13 years ago)

Tweaked comment

  • wp-includes/pluggable.php

     
    2727function wp_set_current_user($id, $name = '') {
    2828        global $current_user;
    2929
    30         if ( isset($current_user) && ($id == $current_user->ID) )
     30        if ( isset( $current_user ) && ( $current_user instanceof WP_User ) && ( $id == $current_user->ID ) )
    3131                return $current_user;
    3232
    33         $current_user = new WP_User($id, $name);
     33        $current_user = new WP_User( $id, $name );
    3434
    35         setup_userdata($current_user->ID);
     35        setup_userdata( $current_user->ID );
    3636
    3737        do_action('set_current_user');
    3838
     
    7575        global $current_user;
    7676
    7777        if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) {
    78                 wp_set_current_user(0);
     78                wp_set_current_user( 0 );
    7979                return false;
    8080        }
    8181
    82         if ( ! empty($current_user) )
    83                 return;
     82        if ( ! empty( $current_user ) ) {
     83                if ( $current_user instanceof WP_User )
     84                        return;
    8485
     86                // Upgrade stdClass to WP_User
     87                if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
     88                        $cur_id = $current_user->ID;
     89                        $current_user = null;
     90                        wp_set_current_user( $cur_id );
     91                        return;
     92                }
     93
     94                // $current_user has a junk value. Force to WP_User with ID 0.
     95                $current_user = null;
     96                wp_set_current_user( 0 );
     97                return false;
     98        }
     99
    85100        if ( ! $user = wp_validate_auth_cookie() ) {
    86                  if ( is_blog_admin() || is_network_admin() || empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) {
    87                         wp_set_current_user(0);
     101                 if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) || !$user = wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' ) ) {
     102                        wp_set_current_user( 0 );
    88103                        return false;
    89104                 }
    90105        }
    91106
    92         wp_set_current_user($user);
     107        wp_set_current_user( $user );
    93108}
    94109endif;
    95110