Make WordPress Core

Ticket #19615: 19615.4.diff

File 19615.4.diff, 4.1 KB (added by swissspidy, 9 years ago)
  • src/wp-includes/pluggable-deprecated.php

    diff --git src/wp-includes/pluggable-deprecated.php src/wp-includes/pluggable-deprecated.php
    index 77690bf..466359e 100644
    if ( !function_exists('get_currentuserinfo') ) : 
    4848function get_currentuserinfo() {
    4949        _deprecated_function( __FUNCTION__, '4.5', 'wp_get_current_user()' );
    5050
    51         return wp_get_current_user();
     51        return _wp_get_current_user();
    5252}
    5353endif;
    5454
  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index 860d802..5c467aa 100644
    if ( !function_exists('wp_get_current_user') ) : 
    6565 * @return WP_User Current WP_User instance.
    6666 */
    6767function wp_get_current_user() {
    68         global $current_user;
    69 
    70         if ( ! empty( $current_user ) ) {
    71                 if ( $current_user instanceof WP_User ) {
    72                         return $current_user;
    73                 }
    74 
    75                 // Upgrade stdClass to WP_User
    76                 if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
    77                         $cur_id = $current_user->ID;
    78                         $current_user = null;
    79                         wp_set_current_user( $cur_id );
    80                         return $current_user;
    81                 }
    82 
    83                 // $current_user has a junk value. Force to WP_User with ID 0.
    84                 $current_user = null;
    85                 wp_set_current_user( 0 );
    86                 return $current_user;
    87         }
    88 
    89         if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) {
    90                 wp_set_current_user( 0 );
    91                 return $current_user;
    92         }
    93 
    94         /**
    95          * Filter the current user.
    96          *
    97          * The default filters use this to determine the current user from the
    98          * request's cookies, if available.
    99          *
    100          * Returning a value of false will effectively short-circuit setting
    101          * the current user.
    102          *
    103          * @since 3.9.0
    104          *
    105          * @param int|bool $user_id User ID if one has been determined, false otherwise.
    106          */
    107         $user_id = apply_filters( 'determine_current_user', false );
    108         if ( ! $user_id ) {
    109                 wp_set_current_user( 0 );
    110                 return $current_user;
    111         }
    112 
    113         wp_set_current_user( $user_id );
    114 
    115         return $current_user;
     68        return _wp_get_current_user();
    11669}
    11770endif;
    11871
  • src/wp-includes/user.php

    diff --git src/wp-includes/user.php src/wp-includes/user.php
    index 8b1b032..64f256f 100644
    function wp_get_users_with_no_role() { 
    24062406
    24072407        return $users;
    24082408}
     2409
     2410/**
     2411 * Retrieve the current user object.
     2412 *
     2413 * Will set the current user, if the current user is not set. The current user
     2414 * will be set to the logged-in person. If no user is logged-in, then it will
     2415 * set the current user to 0, which is invalid and won't have any permissions.
     2416 *
     2417 * This function is used by the pluggable functions {@see wp_get_current_user()}
     2418 * and {@see get_currentuserinfo()}, which is deprecated, for backward compatibility.
     2419 *
     2420 * @since 4.5.0
     2421 * @access private
     2422 *
     2423 * @see https://core.trac.wordpress.org/ticket/19615
     2424 * @global WP_User $current_user Checks if the current user is set.
     2425 *
     2426 * @return WP_User Current WP_User instance.
     2427 */
     2428function _wp_get_current_user() {
     2429        global $current_user;
     2430
     2431        if ( ! empty( $current_user ) ) {
     2432                if ( $current_user instanceof WP_User ) {
     2433                        return $current_user;
     2434                }
     2435
     2436                // Upgrade stdClass to WP_User
     2437                if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
     2438                        $cur_id = $current_user->ID;
     2439                        $current_user = null;
     2440                        wp_set_current_user( $cur_id );
     2441                        return $current_user;
     2442                }
     2443
     2444                // $current_user has a junk value. Force to WP_User with ID 0.
     2445                $current_user = null;
     2446                wp_set_current_user( 0 );
     2447                return $current_user;
     2448        }
     2449
     2450        if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) {
     2451                wp_set_current_user( 0 );
     2452                return $current_user;
     2453        }
     2454
     2455        /**
     2456         * Filter the current user.
     2457         *
     2458         * The default filters use this to determine the current user from the
     2459         * request's cookies, if available.
     2460         *
     2461         * Returning a value of false will effectively short-circuit setting
     2462         * the current user.
     2463         *
     2464         * @since 3.9.0
     2465         *
     2466         * @param int|bool $user_id User ID if one has been determined, false otherwise.
     2467         */
     2468        $user_id = apply_filters( 'determine_current_user', false );
     2469        if ( ! $user_id ) {
     2470                wp_set_current_user( 0 );
     2471                return $current_user;
     2472        }
     2473
     2474        wp_set_current_user( $user_id );
     2475
     2476        return $current_user;
     2477}