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. Built from https://develop.svn.wordpress.org/trunk@36311 git-svn-id: http://core.svn.wordpress.org/trunk@36278 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
16142a461e
commit
283684b616
|
@ -35,6 +35,23 @@ function set_current_user($id, $name = '') {
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
if ( !function_exists('get_currentuserinfo') ) :
|
||||||
|
/**
|
||||||
|
* Populate global variables with information about the currently logged in user.
|
||||||
|
*
|
||||||
|
* @since 0.71
|
||||||
|
* @deprecated 4.5.0 Use wp_get_current_user()
|
||||||
|
* @see wp_get_current_user()
|
||||||
|
*
|
||||||
|
* @return bool|WP_User False on XMLRPC Request and invalid auth cookie, WP_User instance otherwise.
|
||||||
|
*/
|
||||||
|
function get_currentuserinfo() {
|
||||||
|
_deprecated_function( __FUNCTION__, '4.5', 'wp_get_current_user()' );
|
||||||
|
|
||||||
|
return wp_get_current_user();
|
||||||
|
}
|
||||||
|
endif;
|
||||||
|
|
||||||
if ( !function_exists('get_userdatabylogin') ) :
|
if ( !function_exists('get_userdatabylogin') ) :
|
||||||
/**
|
/**
|
||||||
* Retrieve user info by login name.
|
* Retrieve user info by login name.
|
||||||
|
|
|
@ -54,48 +54,30 @@ if ( !function_exists('wp_get_current_user') ) :
|
||||||
/**
|
/**
|
||||||
* Retrieve the current user object.
|
* 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 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
|
* 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.
|
* 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;
|
global $current_user;
|
||||||
|
|
||||||
if ( ! empty( $current_user ) ) {
|
if ( ! empty( $current_user ) ) {
|
||||||
if ( $current_user instanceof WP_User )
|
if ( $current_user instanceof WP_User ) {
|
||||||
return;
|
return $current_user;
|
||||||
|
}
|
||||||
|
|
||||||
// Upgrade stdClass to WP_User
|
// Upgrade stdClass to WP_User
|
||||||
if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
|
if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
|
||||||
$cur_id = $current_user->ID;
|
$cur_id = $current_user->ID;
|
||||||
$current_user = null;
|
$current_user = null;
|
||||||
wp_set_current_user( $cur_id );
|
wp_set_current_user( $cur_id );
|
||||||
return;
|
return $current_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $current_user has a junk value. Force to WP_User with ID 0.
|
// $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 );
|
wp_set_current_user( $user_id );
|
||||||
|
|
||||||
|
return $current_user;
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.5-alpha-36310';
|
$wp_version = '4.5-alpha-36311';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue