Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/22/2014 03:49:43 AM (12 years ago)
Author:
r-a-y
Message:

Blogs: Invalidate total blog count when site is deleted.

This commit:

  • Uses bp_blogs_clear_blog_object_cache() to invalidate the total blog count after a site is deleted and when a site is created.
  • Deprecates bp_blogs_format_clear_blog_cache(), a function that isn't used internally as of this commit, for v2.2.0.
  • Adds a unit test.

Fixes #6062.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-cache.php

    r7918 r9251  
    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}
     
    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
Note: See TracChangeset for help on using the changeset viewer.