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.

git-svn-id: https://develop.svn.wordpress.org/trunk@36311 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2016-01-15 10:15:21 +00:00
parent 053733f8c0
commit c7ae3fb3ee
3 changed files with 28 additions and 28 deletions

View File

@@ -54,48 +54,30 @@ if ( !function_exists('wp_get_current_user') ) :
/**
* Retrieve the current user object.
*
* @since 2.0.3
*
* @global WP_User $current_user
*
* @return WP_User Current user WP_User object
*/
function wp_get_current_user() {
global $current_user;
get_currentuserinfo();
return $current_user;
}
endif;
if ( !function_exists('get_currentuserinfo') ) :
/**
* Populate global variables with information about the currently logged in user.
*
* Will set the current user, if the current user is not set. The current user
* will be set to the logged-in person. If no user is logged-in, then it will
* set the current user to 0, which is invalid and won't have any permissions.
*
* @since 0.71
* @since 2.0.3
*
* @global WP_User $current_user Checks if the current user is set
* @global WP_User $current_user Checks if the current user is set.
*
* @return false|void False on XML-RPC Request and invalid auth cookie.
* @return bool|WP_User WP_User instance on success, false on XMLRPC Request and invalid auth cookie.
*/
function get_currentuserinfo() {
function wp_get_current_user() {
global $current_user;
if ( ! empty( $current_user ) ) {
if ( $current_user instanceof WP_User )
return;
if ( $current_user instanceof WP_User ) {
return $current_user;
}
// Upgrade stdClass to WP_User
if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
$cur_id = $current_user->ID;
$current_user = null;
wp_set_current_user( $cur_id );
return;
return $current_user;
}
// $current_user has a junk value. Force to WP_User with ID 0.
@@ -129,6 +111,8 @@ function get_currentuserinfo() {
}
wp_set_current_user( $user_id );
return $current_user;
}
endif;