From 283684b616ad0c1df013dd6c6f73eed5fae90034 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 15 Jan 2016 10:16:27 +0000 Subject: [PATCH] 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 --- wp-includes/pluggable-deprecated.php | 19 ++++++++++++++- wp-includes/pluggable.php | 36 ++++++++-------------------- wp-includes/version.php | 2 +- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/wp-includes/pluggable-deprecated.php b/wp-includes/pluggable-deprecated.php index 39fcd49d98..77690bf77d 100644 --- a/wp-includes/pluggable-deprecated.php +++ b/wp-includes/pluggable-deprecated.php @@ -35,6 +35,23 @@ function set_current_user($id, $name = '') { } 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') ) : /** * Retrieve user info by login name. @@ -188,4 +205,4 @@ if ( ! class_exists( 'wp_atom_server', false ) ) { _deprecated_function( __CLASS__ . '::' . $name, '3.5', 'the Atom Publishing Protocol plugin' ); } } -} \ No newline at end of file +} diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 4795c213e2..50f626dfcc 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -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; diff --git a/wp-includes/version.php b/wp-includes/version.php index 1f747fb00c..c4cedb0429 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @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.