Ticket #6062: 6062.01.patch
| File 6062.01.patch, 2.6 KB (added by , 11 years ago) |
|---|
-
src/bp-blogs/bp-blogs-cache.php
42 42 * @param int $blog_id ID of the current blog. 43 43 * @param int $user_id ID of the user whose blog cache should be cleared. 44 44 */ 45 function bp_blogs_clear_blog_object_cache( $blog_id , $user_id) {45 function bp_blogs_clear_blog_object_cache( $blog_id = 0, $user_id = 0 ) { 46 46 wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' ); 47 47 wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' ); 48 wp_cache_delete( 'bp_total_blogs', 'bp' ); 48 49 } 49 50 50 51 /** … … 52 53 * 53 54 * @since BuddyPress (1.0.0) 54 55 * 56 * @deprecated BuddyPress (2.2.0) Use bp_blogs_clear_blog_object_cache() instead. 57 * 55 58 * @param BP_Blogs_Blog $recorded_blog_obj The recorded blog, passed by 56 59 * 'bp_blogs_new_blog'. 57 60 */ 58 61 function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) { 59 62 bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id ); 60 wp_cache_delete( 'bp_total_blogs', 'bp' );61 63 } 62 64 63 65 // List actions to clear object caches on 64 66 add_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 ); 67 add_action( 'wpmu_new_blog', 'bp_blogs_clear_blog_object_cache', 10, 2 ); 68 add_action( 'bp_blogs_remove_blog', 'bp_blogs_clear_blog_object_cache' ); 66 69 67 70 // List actions to clear super cached pages on, if super cache is installed 68 71 add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' ); -
tests/phpunit/testcases/blogs/cache.php
231 231 232 232 $this->set_current_user( $old_user ); 233 233 } 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 } 234 268 }