Skip to:
Content

BuddyPress.org

Ticket #6062: 6062.01.patch

File 6062.01.patch, 2.6 KB (added by r-a-y, 5 years ago)
  • 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 ) {
     45function bp_blogs_clear_blog_object_cache( $blog_id = 0, $user_id = 0 ) {
    4646        wp_cache_delete( 'bp_blogs_of_user_'        . $user_id, 'bp' );
    4747        wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
     48        wp_cache_delete( 'bp_total_blogs', 'bp' );
    4849}
    4950
    5051/**
     
    5253 *
    5354 * @since BuddyPress (1.0.0)
    5455 *
     56 * @deprecated BuddyPress (2.2.0) Use bp_blogs_clear_blog_object_cache() instead.
     57 *
    5558 * @param BP_Blogs_Blog $recorded_blog_obj The recorded blog, passed by
    5659 *        'bp_blogs_new_blog'.
    5760 */
    5861function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
    5962        bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
    60         wp_cache_delete( 'bp_total_blogs', 'bp' );
    6163}
    6264
    6365// List actions to clear object caches on
    6466add_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 );
     67add_action( 'wpmu_new_blog',                 'bp_blogs_clear_blog_object_cache', 10, 2 );
     68add_action( 'bp_blogs_remove_blog',          'bp_blogs_clear_blog_object_cache' );
    6669
    6770// List actions to clear super cached pages on, if super cache is installed
    6871add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
  • tests/phpunit/testcases/blogs/cache.php

     
    231231
    232232                $this->set_current_user( $old_user );
    233233        }
     234
     235        /**
     236         * @group bp_blogs_total_blogs
     237         */
     238        public function test_bp_blogs_total_blogs_count_after_delete_blog() {
     239                if ( ! is_multisite() ) {
     240                        return;
     241                }
     242
     243                $u = $this->factory->user->create();
     244
     245                // need to make sure we set the 'public' flag due to how BP_Blogs_Blogs:get_all() works
     246                $b1 = $this->factory->blog->create( array(
     247                        'meta' => array(
     248                                'public' => 1
     249                        )
     250                ) );
     251                $b2 = $this->factory->blog->create( array(
     252                        'meta' => array(
     253                                'public' => 1
     254                        )
     255                ) );
     256
     257                bp_blogs_record_blog( $b1, $u );
     258                bp_blogs_record_blog( $b2, $u );
     259
     260                // prime total blog count
     261                bp_blogs_total_blogs();
     262
     263                // delete a blog
     264                wpmu_delete_blog( $b2 );
     265
     266                $this->assertEquals( 1, bp_blogs_total_blogs() );
     267        }
    234268}