Make WordPress Core

Changeset 36311

Timestamp:
01/15/2016 10:15:21 AM (9 years ago)
Author:
swissspidy
Message:

Users: Deprecate the get_currentuserinfo() pluggable function.

It encourages an ugly pattern like global $userdata; get_currentuserinfo(); in plugins/themes. wp_get_current_user() should be used instead, e.g. $current_user = wp_get_current_user();.

Props scribu for initial patch.
Fixes #19615.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable-deprecated.php

    r34348 r36311  
    3333    _deprecated_function( __FUNCTION__, '3.0', 'wp_set_current_user()' );
    3434    return wp_set_current_user($id, $name);
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
    3552}
    3653endif;
  • trunk/src/wp-includes/pluggable.php

    r36246 r36311  
    5555 * Retrieve the current user object.
    5656 *
    57  * @since 2.0.3
    58  *
    59  * @global WP_User $current_user
    60  *
    61  * @return WP_User Current user WP_User object
    62  */
    63 function wp_get_current_user() {
    64     global $current_user;
    65 
    66     get_currentuserinfo();
    67 
    68     return $current_user;
    69 }
    70 endif;
    71 
    72 if ( !function_exists('get_currentuserinfo') ) :
    73 /**
    74  * Populate global variables with information about the currently logged in user.
    75  *
    7657 * Will set the current user, if the current user is not set. The current user
    7758 * will be set to the logged-in person. If no user is logged-in, then it will
    7859 * set the current user to 0, which is invalid and won't have any permissions.
    7960 *
    80  * @since 0.71
    81  *
    82  * @global WP_User $current_user Checks if the current user is set
    83  *
    84  * @return false|void False on XML-RPC Request and invalid auth cookie.
    85  */
    86 function get_currentuserinfo() {
     61 * @since
     62 *
     63 * @global WP_User $current_user Checks if the current user is set
     64 *
     65 * @return RPC Request and invalid auth cookie.
     66 */
     67function () {
    8768    global $current_user;
    8869
    8970    if ( ! empty( $current_user ) ) {
    90         if ( $current_user instanceof WP_User )
    91             return;
     71        if ( $current_user instanceof WP_User ) {
     72            return $current_user;
     73        }
    9274
    9375        // Upgrade stdClass to WP_User
     
    9678            $current_user = null;
    9779            wp_set_current_user( $cur_id );
    98             return;
     80            return;
    9981        }
    10082
     
    130112
    131113    wp_set_current_user( $user_id );
     114
     115
    132116}
    133117endif;
  • trunk/tests/phpunit/tests/pluggable.php

    r35148 r36311  
    128128            'wp_set_current_user'             => array( 'id', 'name' => '' ),
    129129            'wp_get_current_user'             => array(),
    130             'get_currentuserinfo'             => array(),
    131130            'get_userdata'                    => array( 'user_id' ),
    132131            'get_user_by'                     => array( 'field', 'value' ),
Note: See TracChangeset for help on using the changeset viewer.