Skip to:
Content

BuddyPress.org

Ticket #6062: 6062.02.patch

File 6062.02.patch, 3.5 KB (added by r-a-y, 5 years ago)

02.patch properly deprecates bp_blogs_format_clear_blog_cache() and tweaks bp_blogs_clear_blog_object_cache() to check for the user ID.

  • src/bp-blogs/bp-blogs-cache.php

     
    4242 * @param int $blog_id ID of the current blog.
    4343 * @param int $user_id ID of the user whose blog cache should be cleared.
    4444 */
    45 function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
    46         wp_cache_delete( 'bp_blogs_of_user_'        . $user_id, 'bp' );
    47         wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
    48 }
     45function bp_blogs_clear_blog_object_cache( $blog_id = 0, $user_id = 0 ) {
     46        if ( ! empty( $user_id ) ) {
     47                wp_cache_delete( 'bp_blogs_of_user_'        . $user_id, 'bp' );
     48                wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
     49        }
    4950
    50 /**
    51  * Clear cache when a new blog is created.
    52  *
    53  * @since BuddyPress (1.0.0)
    54  *
    55  * @param BP_Blogs_Blog $recorded_blog_obj The recorded blog, passed by
    56  *        'bp_blogs_new_blog'.
    57  */
    58 function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
    59         bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
    6051        wp_cache_delete( 'bp_total_blogs', 'bp' );
    6152}
    6253
    6354// List actions to clear object caches on
    6455add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
    65 add_action( 'bp_blogs_new_blog',             'bp_blogs_format_clear_blog_cache', 10, 2 );
     56add_action( 'wpmu_new_blog',                 'bp_blogs_clear_blog_object_cache', 10, 2 );
     57add_action( 'bp_blogs_remove_blog',          'bp_blogs_clear_blog_object_cache' );
    6658
    6759// List actions to clear super cached pages on, if super cache is installed
    6860add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
  • src/bp-core/deprecated/2.2.php

     
    6363        _deprecated_function( __FUNCTION__, '2.2', 'bp_activity_post_type_update()' );
    6464        bp_activity_post_type_update( $post );
    6565}
     66
     67/**
     68 * Clear cache when a new blog is created.
     69 *
     70 * @since BuddyPress (1.0.0)
     71 * @deprecated BuddyPress (2.2.0)
     72 *
     73 * @param BP_Blogs_Blog $recorded_blog_obj The recorded blog, passed by
     74 *        'bp_blogs_new_blog'.
     75 */
     76function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
     77        _deprecated_function( __FUNCTION__, '2.2', 'bp_blogs_clear_blog_object_cache()' );
     78        bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
     79}
  • tests/phpunit/testcases/blogs/cache.php

     
    254254                // check if function references cache or hits the DB by comparing query count
    255255                $this->assertEquals( $first_query_count, $wpdb->num_queries );
    256256        }
     257
     258        /**
     259         * @group bp_blogs_total_blogs
     260         */
     261        public function test_bp_blogs_total_blogs_count_after_delete_blog() {
     262                if ( ! is_multisite() ) {
     263                        return;
     264                }
     265
     266                $u = $this->factory->user->create();
     267
     268                // need to make sure we set the 'public' flag due to how BP_Blogs_Blogs:get_all() works
     269                $b1 = $this->factory->blog->create( array(
     270                        'meta' => array(
     271                                'public' => 1
     272                        )
     273                ) );
     274                $b2 = $this->factory->blog->create( array(
     275                        'meta' => array(
     276                                'public' => 1
     277                        )
     278                ) );
     279
     280                bp_blogs_record_blog( $b1, $u );
     281                bp_blogs_record_blog( $b2, $u );
     282
     283                // prime total blog count
     284                bp_blogs_total_blogs();
     285
     286                // delete a blog
     287                wpmu_delete_blog( $b2 );
     288
     289                $this->assertEquals( 1, bp_blogs_total_blogs() );
     290        }
    257291}