Skip to:
Content

bbPress.org

Ticket #2813: 2813.01.patch

File 2813.01.patch, 4.0 KB (added by thebrandonallen, 7 years ago)
  • src/includes/core/actions.php

    diff --git src/includes/core/actions.php src/includes/core/actions.php
    index 40f9dd4..5231a9c 100644
    add_action( 'bbp_new_reply_pre_extras', 'bbp_clean_post_cache' ); 
    295295add_action( 'bbp_new_reply_post_extras', 'bbp_clean_post_cache' );
    296296
    297297// Clean bbPress post caches when WordPress's is cleaned
    298 add_action( 'clean_post_cache', 'bbp_clean_post_cache' );
     298add_action( 'clean_post_cache', 'bbp_clean_post_cache', 10, 2 );
    299299
    300300/**
    301301 * bbPress needs to redirect the user around in a few different circumstances:
  • src/includes/core/cache.php

    diff --git src/includes/core/cache.php src/includes/core/cache.php
    index 4734d13..f703dbe 100644
    new BBP_Skip_Children(); 
    130130 *
    131131 * @since bbPress (r4040)
    132132 *
     133 * @param mixed $post The post object or ID to remove from the cache. Defaults to null.
     134 * @param mixed $post_object The post object to remove from the cache. Defaults to null.
     135 * @uses get_post() To get the post object.
     136 * @uses bbp_get_forum_post_type() To get the forum post type.
     137 * @uses bbp_get_topic_post_type() To get the topic post type.
     138 * @uses bbp_get_reply_post_type() To get the reply post type.
     139 * @uses wp_cache_delete() To delete the cache item.
     140 * @uses clean_object_term_cache() To clean the term cache.
     141 * @uses bbp_clean_post_cache() Recursion.
    133142 * @uses do_action() Calls 'bbp_clean_post_cache' on $id
    134  * @param object|int $_post The post object or ID to remove from the cache
    135143 */
    136 function bbp_clean_post_cache( $_post = '' ) {
     144function bbp_clean_post_cache( $post = null, $post_object = null ) {
     145
     146        // Make sure $post_object is a WP_Post object
     147        if ( $post_object instanceof WP_Post ) {
     148                $post = $post_object;
     149        }
    137150
    138151        // Bail if no post
    139         $_post = get_post( $_post );
    140         if ( empty( $_post ) ) {
     152        $post = get_post( $post );
     153        if ( empty( $post ) ) {
    141154                return;
    142155        }
    143156
    function bbp_clean_post_cache( $_post = '' ) { 
    149162        );
    150163
    151164        // Bail if not a bbPress post type
    152         if ( ! in_array( $_post->post_type, $post_types, true ) ) {
     165        if ( ! in_array( $post->post_type, $post_types, true ) ) {
    153166                return;
    154167        }
    155168
    156         wp_cache_delete( $_post->ID, 'posts'     );
    157         wp_cache_delete( $_post->ID, 'post_meta' );
     169        wp_cache_delete( $post->ID, 'posts'     );
     170        wp_cache_delete( $post->ID, 'post_meta' );
    158171
    159         clean_object_term_cache( $_post->ID, $_post->post_type );
     172        clean_object_term_cache( $post->ID, $post->post_type );
    160173
    161         do_action( 'bbp_clean_post_cache', $_post->ID, $_post );
     174        do_action( 'bbp_clean_post_cache', $post->ID, $post );
    162175
    163176        // Loop through query types and clean caches
    164177        foreach ( $post_types as $post_type ) {
    165                 wp_cache_delete( 'bbp_get_forum_'     . $_post->ID . '_reply_id',                              'bbpress_posts' );
    166                 wp_cache_delete( 'bbp_parent_'        . $_post->ID . '_type_' . $post_type . '_child_last_id', 'bbpress_posts' );
    167                 wp_cache_delete( 'bbp_parent_'        . $_post->ID . '_type_' . $post_type . '_child_count',   'bbpress_posts' );
    168                 wp_cache_delete( 'bbp_parent_public_' . $_post->ID . '_type_' . $post_type . '_child_ids',     'bbpress_posts' );
    169                 wp_cache_delete( 'bbp_parent_all_'    . $_post->ID . '_type_' . $post_type . '_child_ids',     'bbpress_posts' );
     178                wp_cache_delete( 'bbp_get_forum_'     . $post->ID . '_reply_id',                              'bbpress_posts' );
     179                wp_cache_delete( 'bbp_parent_'        . $post->ID . '_type_' . $post_type . '_child_last_id', 'bbpress_posts' );
     180                wp_cache_delete( 'bbp_parent_'        . $post->ID . '_type_' . $post_type . '_child_count',   'bbpress_posts' );
     181                wp_cache_delete( 'bbp_parent_public_' . $post->ID . '_type_' . $post_type . '_child_ids',     'bbpress_posts' );
     182                wp_cache_delete( 'bbp_parent_all_'    . $post->ID . '_type_' . $post_type . '_child_ids',     'bbpress_posts' );
    170183        }
    171184
    172185        // Invalidate parent caches
    173         if ( ! empty( $_post->post_parent ) ) {
    174                 bbp_clean_post_cache( $_post->post_parent );
     186        if ( ! empty( $post->post_parent ) ) {
     187                bbp_clean_post_cache( $post->post_parent );
    175188        }
    176189}