WordPress.org

Make WordPress Core

Ticket #10758: 10758-wp-includes-pluggable.patch

File 10758-wp-includes-pluggable.patch, 2.6 KB (added by hakre, 5 years ago)

That global variable is not always an object of class WP_User + global and variable hints

  • wp-includes/pluggable.php

    ### Eclipse Workspace Patch 1.0
    #P wordpress-trunk
     
    3535 * actions on users who aren't signed in. 
    3636 * 
    3737 * @since 2.0.3 
    38  * @global object $current_user The current user object which holds the user data. 
     38 * @global WP_User $current_user User-object of request aka The current user object which holds the user data. 
    3939 * @uses do_action() Calls 'set_current_user' hook after setting the current user. 
    4040 * 
    4141 * @param int $id User ID 
     
    4343 * @return WP_User Current user User object 
    4444 */ 
    4545function wp_set_current_user($id, $name = '') { 
     46        /* @var $current_user WP_User */ 
    4647        global $current_user; 
    4748 
    4849        if ( isset($current_user) && ($id == $current_user->ID) ) 
     
    6364 * Retrieve the current user object. 
    6465 * 
    6566 * @since 2.0.3 
     67 * @global WP_User $current_user User-object of request aka The current user object which holds the user data. 
    6668 * 
    6769 * @return WP_User Current user WP_User object 
    6870 */ 
    6971function wp_get_current_user() { 
     72        /* @var $current_user WP_User */ 
    7073        global $current_user; 
    7174 
    7275        get_currentuserinfo(); 
     
    8487 * set the current user to 0, which is invalid and won't have any permissions. 
    8588 * 
    8689 * @since 0.71 
    87  * @uses $current_user Checks if the current user is set 
     90 * @global WP_User $current_user User-object of request aka The current user object which holds the user data. 
    8891 * @uses wp_validate_auth_cookie() Retrieves current logged in user. 
    8992 * 
    90  * @return bool|null False on XMLRPC Request and invalid auth cookie. Null when current user set 
     93 * @return bool|null False on XMLRPC Request and invalid auth cookie. Null when current user set or it was not empty 
    9194 */ 
    9295function get_currentuserinfo() { 
     96        /* @var $current_user WP_User */ 
    9397        global $current_user; 
    9498 
    9599        if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) 
    96100                return false; 
    97101 
    98102        if ( ! empty($current_user) ) 
    99                 return; 
     103                return null; 
    100104 
    101105        if ( ! $user = wp_validate_auth_cookie() ) { 
    102106                 if ( empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) { 
     
    106110        } 
    107111 
    108112        wp_set_current_user($user); 
     113 
     114        return null; 
    109115} 
    110116endif; 
    111117 
     
    12231229 * @return string The one use form token 
    12241230 */ 
    12251231function wp_create_nonce($action = -1) { 
     1232        /* @var $user WP_User */ 
    12261233        $user = wp_get_current_user(); 
    1227         $uid = (int) $user->id; 
    12281234 
     1235        if ( is_object($user) )  
     1236                $uid = (int) $user->id; 
     1237        else 
     1238                $uid = 0; 
     1239 
    12291240        $i = wp_nonce_tick(); 
    12301241 
    12311242        return substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10);