WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/15/2016 10:15:21 AM (4 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 2.0.3
     62 *
     63 * @global WP_User $current_user Checks if the current user is set.
     64 *
     65 * @return bool|WP_User WP_User instance on success, false on XMLRPC Request and invalid auth cookie.
     66 */
     67function wp_get_current_user() {
    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 $current_user;
    9981        }
    10082
     
    130112
    131113    wp_set_current_user( $user_id );
     114
     115    return $current_user;
    132116}
    133117endif;
Note: See TracChangeset for help on using the changeset viewer.