Skip to:
Content

BuddyPress.org

Ticket #7595: 7595.diff

File 7595.diff, 4.4 KB (added by johnjamesjacoby, 7 years ago)
  • src/bp-core/classes/class-bp-core-user.php

     
    749749        /**
    750750         * Get WordPress user details for a specified user.
    751751         *
    752          * @global wpdb $wpdb WordPress database object.
     752         * @since 3.0.0 Results might be from cache
    753753         *
    754754         * @param int $user_id User ID.
    755          * @return array Associative array.
     755         * @return false|object WP_User if successful, false on failure.
    756756         */
    757757        public static function get_core_userdata( $user_id ) {
    758                 global $wpdb;
    759 
    760                 if ( !$user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->users} WHERE ID = %d LIMIT 1", $user_id ) ) )
    761                         return false;
    762 
    763                 return $user;
     758                return WP_User::get_data_by( 'id', $user_id );
    764759        }
    765760
    766761        /**
  • src/bp-core/classes/class-bp-user-query.php

     
    570570
    571571                ), $this ) );
    572572
    573                 // WP_User_Query doesn't cache the data it pulls from wp_users,
    574                 // and it does not give us a way to save queries by fetching
    575                 // only uncached users. However, BP does cache this data, so
    576                 // we set it here.
    577                 foreach ( $wp_user_query->results as $u ) {
    578                         wp_cache_set( 'bp_core_userdata_' . $u->ID, $u, 'bp' );
    579                 }
    580 
    581573                // We calculate total_users using a standalone query, except
    582574                // when a whitelist of user_ids is passed to the constructor.
    583575                // This clause covers the latter situation, and ensures that
  • src/bp-members/bp-members-functions.php

     
    214214                return false;
    215215        }
    216216
    217         $userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' );
     217        // Get core user data
     218        $userdata = BP_Core_User::get_core_userdata( $user_id );
    218219
    219         // No cache.
    220         if ( false === $userdata ) {
    221                 $userdata = BP_Core_User::get_core_userdata( $user_id );
    222 
    223                 // Cache data; no-result is cached as integer 0.
    224                 wp_cache_set( 'bp_core_userdata_' . $user_id, false === $userdata ? 0 : $userdata, 'bp' );
    225 
    226         // Cached no-result, so set return value as false as expected.
    227         } elseif ( 0 === $userdata ) {
    228                 $userdata = false;
    229         }
    230 
    231220        /**
    232221         * Filters the userdata for a passed user.
    233222         *
  • src/bp-settings/bp-settings-actions.php

     
    178178                // Clear cached data, so that the changed settings take effect
    179179                // on the current page load.
    180180                if ( ( false === $email_error ) && ( false === $pass_error ) && ( wp_update_user( $update_user ) ) ) {
    181                         wp_cache_delete( 'bp_core_userdata_' . bp_displayed_user_id(), 'bp' );
    182181                        $bp->displayed_user->userdata = bp_core_get_core_userdata( bp_displayed_user_id() );
    183182                }
    184183
     
    454453                ) );
    455454
    456455                if ( $email_changed ) {
    457                         // Delete object cache for displayed user.
    458                         wp_cache_delete( 'bp_core_userdata_' . bp_displayed_user_id(), 'bp' );
    459456
    460457                        // Delete the pending email change key.
    461458                        bp_delete_user_meta( bp_displayed_user_id(), 'pending_email_change' );
  • src/bp-xprofile/bp-xprofile-functions.php

     
    836836        bp_update_user_meta( $user_id, 'last_name',  $lastname  );
    837837
    838838        wp_update_user( array( 'ID' => $user_id, 'display_name' => $fullname ) );
    839         wp_cache_delete( 'bp_core_userdata_' . $user_id, 'bp' );
    840839}
    841840add_action( 'xprofile_updated_profile', 'xprofile_sync_wp_profile' );
    842841add_action( 'bp_core_signup_user',      'xprofile_sync_wp_profile' );
  • tests/phpunit/testcases/members/cache.php

     
    7878                $this->assertEqualSets( $b1, $b2 );
    7979                $this->assertSame( $num_queries, $wpdb->num_queries );
    8080        }
    81 
    82         /**
    83          * @group bp_core_get_core_userdata
    84          */
    85         public function test_bp_core_get_core_userdata_should_cache_no_results() {
    86                 // Get the userdata for a user that doesn't exist.
    87                 bp_core_get_core_userdata( PHP_INT_MAX );
    88 
    89                 // Assert that the non-existent user's attempt was cached.
    90                 $this->assertNotFalse( wp_cache_get( 'bp_core_userdata_' . PHP_INT_MAX, 'bp' ) );
    91         }
    9281}
    9382