mirror of
git://develop.git.wordpress.org/
synced 2025-04-08 14:13:27 +02:00
Users: Revert use of shared objects for current user.
Reverts [50790]. Props oztaser, ravipatel, dd32, costdev, SergeyBiryukov, tykoted, cu121, xknown. Merges [54397] to the 6.0 branch. Fixes #54984. git-svn-id: https://develop.svn.wordpress.org/branches/6.0@54544 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
863c5c46da
commit
79f361f47d
@ -91,7 +91,6 @@ if ( ! function_exists( 'get_user_by' ) ) :
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
|
||||
* @since 5.8.0 Returns the global `$current_user` if it's the user being fetched.
|
||||
*
|
||||
* @global WP_User $current_user The current user object which holds the user data.
|
||||
*
|
||||
@ -100,18 +99,12 @@ if ( ! function_exists( 'get_user_by' ) ) :
|
||||
* @return WP_User|false WP_User object on success, false on failure.
|
||||
*/
|
||||
function get_user_by( $field, $value ) {
|
||||
global $current_user;
|
||||
|
||||
$userdata = WP_User::get_data_by( $field, $value );
|
||||
|
||||
if ( ! $userdata ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $current_user instanceof WP_User && $current_user->ID === (int) $userdata->ID ) {
|
||||
return $current_user;
|
||||
}
|
||||
|
||||
$user = new WP_User;
|
||||
$user->init( $userdata );
|
||||
|
||||
|
@ -1854,15 +1854,10 @@ function update_user_caches( $user ) {
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 4.4.0 'clean_user_cache' action was added.
|
||||
* @since 5.8.0 Refreshes the global user instance if cleaning the user cache for the current user.
|
||||
*
|
||||
* @global WP_User $current_user The current user object which holds the user data.
|
||||
*
|
||||
* @param WP_User|int $user User object or ID to be cleaned from the cache
|
||||
*/
|
||||
function clean_user_cache( $user ) {
|
||||
global $current_user;
|
||||
|
||||
if ( is_numeric( $user ) ) {
|
||||
$user = new WP_User( $user );
|
||||
}
|
||||
@ -1885,13 +1880,6 @@ function clean_user_cache( $user ) {
|
||||
* @param WP_User $user User object.
|
||||
*/
|
||||
do_action( 'clean_user_cache', $user->ID, $user );
|
||||
|
||||
// Refresh the global user instance if the cleaning current user.
|
||||
if ( get_current_user_id() === (int) $user->ID ) {
|
||||
$user_id = (int) $user->ID;
|
||||
$current_user = null;
|
||||
wp_set_current_user( $user_id, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -339,19 +339,4 @@ class Tests_Pluggable extends WP_UnitTestCase {
|
||||
return $signatures;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28020
|
||||
*/
|
||||
public function test_get_user_by_should_return_same_instance_as_wp_get_current_user() {
|
||||
// Create a test user.
|
||||
$new_user = self::factory()->user->create( array( 'role' => 'subscriber' ) );
|
||||
|
||||
// Set the test user as the current user.
|
||||
$current_user = wp_set_current_user( $new_user );
|
||||
|
||||
// Get the test user using get_user_by().
|
||||
$from_get_user_by = get_user_by( 'id', $new_user );
|
||||
|
||||
$this->assertSame( $current_user, $from_get_user_by );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user