WordPress.org

Make WordPress Core

Ticket #15565: 15565.2.diff

File 15565.2.diff, 2.3 KB (added by mdawaffe, 7 years ago)

Option 2

  • wp-includes/post.php

     
    42404240 * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any).
    42414241 *
    42424242 * @param int $id The Post ID in the cache to clean
     4243 * @param string|array $context The reason(s) the cache is being cleaned
    42434244 */
    4244 function clean_post_cache($id) {
     4245function clean_post_cache( $id, $context = array() ) {
    42454246        global $_wp_suspend_cache_invalidation, $wpdb;
    42464247
    42474248        if ( !empty($_wp_suspend_cache_invalidation) )
     
    42594260
    42604261        wp_cache_delete( 'wp_get_archives', 'general' );
    42614262
    4262         do_action('clean_post_cache', $id);
     4263        $context = (array) $context;
     4264        do_action( 'clean_post_cache', $id, $context );
    42634265
    42644266        if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) {
     4267                if ( !in_array( 'recurse', $context ) )
     4268                        $context[] = 'recurse';
     4269
    42654270                foreach ( $children as $cid ) {
    42664271                        // Loop detection
    42674272                        if ( $cid == $id )
    42684273                                continue;
    4269                         clean_post_cache( $cid );
     4274                        clean_post_cache( $cid, $context );
    42704275                }
    42714276        }
    42724277
     
    43024307 * @uses do_action() Will call the 'clean_page_cache' hook action.
    43034308 *
    43044309 * @param int $id Page ID to clean
     4310 * @param string|array $context The reason(s) the cache is being cleaned
    43054311 */
    4306 function clean_page_cache($id) {
    4307         clean_post_cache($id);
     4312function clean_page_cache( $id, $context = array() ) {
     4313        clean_post_cache( $id, $context );
    43084314
    43094315        wp_cache_delete( 'all_page_ids', 'posts' );
    43104316        wp_cache_delete( 'get_pages', 'posts' );
    43114317
    4312         do_action('clean_page_cache', $id);
     4318        do_action( 'clean_page_cache', $id, (array) $context );
    43134319}
    43144320
    43154321/**
  • wp-includes/comment.php

     
    15651565        $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
    15661566
    15671567        if ( 'page' == $post->post_type )
    1568                 clean_page_cache( $post_id );
     1568                clean_page_cache( $post_id, 'comment_count' );
    15691569        else
    1570                 clean_post_cache( $post_id );
     1570                clean_post_cache( $post_id, 'comment_count' );
    15711571
    15721572        do_action('wp_update_comment_count', $post_id, $new, $old);
    15731573        do_action('edit_post', $post_id, $post);