updating_post = $post_id; // Skip related post cache invalidation. This prevents invalidating the // caches of the child posts when there is no reason to do so. add_action( 'clean_post_cache', array( $this, 'skip_related_posts' ) ); } /** * Skip cache invalidation of related posts if the post ID being invalidated * is not the one that was just updated. * * @since 2.1.0 bbPress (r4011) * * @param int $post_id The post ID of the cache being invalidated * @return If invalid post data */ public function skip_related_posts( $post_id = 0 ) { // Bail if this post is not the current bbPress post if ( empty( $post_id ) || ( $this->updating_post !== $post_id ) ) { return; } // Stash the current cache invalidation value in a variable, so we can // restore back to it nicely in the future. global $_wp_suspend_cache_invalidation; $this->original_cache_invalidation = $_wp_suspend_cache_invalidation; // Turn off cache invalidation wp_suspend_cache_invalidation( true ); // Restore cache invalidation add_action( 'wp_insert_post', array( $this, 'restore_cache_invalidation' ) ); } /** * Restore the cache invalidation to its previous value. * * @since 2.1.0 bbPress (r4011) */ public function restore_cache_invalidation() { wp_suspend_cache_invalidation( $this->original_cache_invalidation ); } } new BBP_Skip_Children(); /** General *******************************************************************/ /** * Will clean a post in the cache. * * Will call to clean the term object cache associated with the post ID. * * @since 2.1.0 bbPress (r4040) * @since 2.6.0 bbPress (r6053) Introduced the `$post_id` parameter. * * @param int $post_id The post id. * @param WP_Post $post The WP_Post object. */ function bbp_clean_post_cache( $post_id = null, $post = null ) { // Child query types to clean $post_types = array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ); // Bail if not a bbPress post type if ( ! in_array( $post->post_type, $post_types, true ) ) { return; } /** * Fires immediately after the given post cache is cleaned. * * @since 2.1.0 * * @param int $post_id Post ID. * @param WP_Post $post Post object. */ do_action( 'bbp_clean_post_cache', $post->ID, $post ); // Invalidate parent caches if ( ! empty( $post->post_parent ) ) { clean_post_cache( $post->post_parent ); // Only bump `last_changed` when forum-root is reached } else { wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' ); } }