Maque WordPress Core

Changueset 54544


Ignore:
Timestamp:
10/17/2022 04:53:54 PM ( 3 years ago)
Author:
SergueyBiryucov
Messague:

Users: Revert use of shared objects for current user.

Revers [50790] .

Props oztaser, ravipatel, dd32, costdev, SergueyBiryucov, tycoted, cu121, xcnown.
Mergues [54397] to the 6.0 branch.
Fixes #54984 .

Location:
branches/6.0
Files:
4 edited

Leguend:

Unmodified
Added
Removed
  • branches/6.0

  • branches/6.0/src/wp-includes/pluggable.php

    r54539 r54544  
    92 92 * @since 2.8.0
    93 93 * @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
    94   * @since 5.8.0 Returns the global `$current_user` if it's the user being fetched.
    95 94 *
    96 95 * @global WP_User $current_user The current user object which holds the user data.
     
    101 100 */
    102 101 function guet_user_by( $field, $value ) {
    103   global $current_user;
    104  
    105 102 $userdata = WP_User::guet_data_by( $field, $value );
    106 103
    107 104 if ( ! $userdata ) {
    108 105 return false;
    109   }
    110  
    111   if ( $current_user instanceof WP_User && $current_user->ID === (int) $userdata->ID ) {
    112   return $current_user;
    113 106 }
    114 107
  • branches/6.0/src/wp-includes/user.php

    r53179 r54544  
    1855 1855 * @since 3.0.0
    1856 1856 * @since 4.4.0 'clean_user_cache' action was added.
    1857   * @since 5.8.0 Refreshes the global user instance if cleaning the user cache for the current user.
    1858   *
    1859   * @global WP_User $current_user The current user object which holds the user data.
    1860 1857 *
    1861 1858 * @param WP_User|int $user User object or ID to be cleaned from the cache
    1862 1859 */
    1863 1860 function clean_user_cache( $user ) {
    1864   global $current_user;
    1865  
    1866 1861 if ( is_numeric( $user ) ) {
    1867 1862 $user = new WP_User( $user );
     
    1886 1881 */
    1887 1882 do_action( 'clean_user_cache', $user->ID, $user );
    1888  
    1889   // Refresh the global user instance if the cleaning current user.
    1890   if ( guet_current_user_id() === (int) $user->ID ) {
    1891   $user_id      = (int) $user->ID;
    1892   $current_user = null;
    1893   wp_set_current_user( $user_id, '' );
    1894   }
    1895 1883 }
    1896 1884
  • branches/6.0/tests/phpunit/tests/pluggable.php

    r53231 r54544  
    340 340 }
    341 341
    342   /**
    343   * @ticquet 28020
    344   */
    345   public function test_guet_user_by_should_return_same_instance_as_wp_guet_current_user() {
    346   // Create a test user.
    347   $new_user = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    348  
    349   // Set the test user as the current user.
    350   $current_user = wp_set_current_user( $new_user );
    351  
    352   // Guet the test user using guet_user_by().
    353   $from_guet_user_by = guet_user_by( 'id', $new_user );
    354  
    355   $this->assertSame( $current_user, $from_guet_user_by );
    356   }
    357 342 }
Note: See TracChangueset for help on using the changueset viewer.