WordPress.org

Make WordPress Core

Ticket #20486: 20486.diff

File 20486.diff, 5.5 KB (added by duck_, 6 years ago)
  • wp-includes/comment.php

     
    15791579        $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) );
    15801580        $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
    15811581
    1582         clean_post_cache( $post_id, $post->post_type );
     1582        clean_post_cache( $post );
    15831583
    15841584        do_action('wp_update_comment_count', $post_id, $new, $old);
    15851585        do_action('edit_post', $post_id, $post);
  • wp-includes/post.php

     
    13611361        $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db');
    13621362        $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
    13631363
    1364         clean_post_cache( $post_id, $post_type );
     1364        clean_post_cache( $post_id );
    13651365
    13661366        return $return;
    13671367}
     
    20452045        $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) );
    20462046        do_action( 'deleted_post', $postid );
    20472047
    2048         clean_post_cache( $postid, $post->post_type );
     2048        clean_post_cache( $post );
    20492049
    20502050        if ( is_post_type_hierarchical( $post->post_type ) ) {
    20512051                foreach ( (array) $children as $child )
    2052                         clean_post_cache( $child->ID, $child->post_type );
     2052                        clean_post_cache( $child );
    20532053        }
    20542054
    20552055        wp_clear_scheduled_hook('publish_future_post', array( $postid ) );
     
    26282628
    26292629        $current_guid = get_post_field( 'guid', $post_ID );
    26302630
    2631         clean_post_cache( $post_ID, $data['post_type'] );
     2631        clean_post_cache( $post_ID );
    26322632
    26332633        // Set GUID
    26342634        if ( !$update && '' == $current_guid )
     
    37333733        if ( $file )
    37343734                update_attached_file( $post_ID, $file );
    37353735
    3736         clean_post_cache( $post_ID, $post_type );
     3736        clean_post_cache( $post_ID );
    37373737
    37383738        if ( ! empty( $context ) )
    37393739                add_post_meta( $post_ID, '_wp_attachment_context', $context, true );
     
    38383838        if ( ! empty($file) )
    38393839                @ unlink($file);
    38403840
    3841         clean_post_cache( $post_id, $post->post_type );
     3841        clean_post_cache( $post );
    38423842
    38433843        return $post;
    38443844}
     
    43194319 *
    43204320 * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any).
    43214321 *
    4322  * @param int $id The Post ID in the cache to clean
    4323  * @param string $post_type The post_type of the post. Defaults to "post"
     4322 * @param object $post The post to remove from the cache
    43244323 */
    4325 function clean_post_cache($id, $post_type = 'post') {
     4324function clean_post_cache( $post ) {
    43264325        global $_wp_suspend_cache_invalidation, $wpdb;
    43274326
    43284327        if ( ! empty( $_wp_suspend_cache_invalidation ) )
    43294328                return;
    43304329
    4331         $id = (int) $id;
     4330        if ( is_numeric( $post ) )
     4331                $post = get_post( $post );
    43324332
    4333         if ( 0 === $id )
     4333        if ( empty( $post ) )
    43344334                return;
    43354335
    4336         wp_cache_delete($id, 'posts');
    4337         wp_cache_delete($id, 'post_meta');
     4336        wp_cache_delete( $post->ID, 'posts' );
     4337        wp_cache_delete( $post->ID, 'post_meta' );
    43384338
    4339         clean_object_term_cache( $id, $post_type );
     4339        clean_object_term_cache( $post->ID, $post->post_type );
    43404340
    43414341        wp_cache_delete( 'wp_get_archives', 'general' );
    43424342
    4343         do_action( 'clean_post_cache', $id, $post_type );
     4343        do_action( 'clean_post_cache', $post->ID, $post );
    43444344
    4345         if ( 'page' == $post_type ) {
     4345        if ( 'page' == $post->post_type ) {
    43464346                wp_cache_delete( 'all_page_ids', 'posts' );
    43474347                wp_cache_delete( 'get_pages', 'posts' );
    4348                 do_action( 'clean_page_cache', $id );
     4348                do_action( 'clean_page_cache', $post->ID );
    43494349        }
    43504350
    4351         if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) {
    4352                 foreach ( $children as $cid ) {
     4351        if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $post->ID) ) ) {
     4352                foreach ( $children as $child ) {
    43534353                        // Loop detection
    4354                         if ( $cid->ID == $id )
     4354                        if ( $child->ID == $post->ID )
    43554355                                continue;
    4356                         clean_post_cache( $cid->ID, $cid->post_type );
     4356                        clean_post_cache( $child );
    43574357                }
    43584358        }
    43594359
    43604360        if ( is_multisite() )
    4361                 wp_cache_delete( $wpdb->blogid . '-' . $id, 'global-posts' );
     4361                wp_cache_delete( $wpdb->blogid . '-' . $post->ID, 'global-posts' );
    43624362}
    43634363
    43644364/**
     
    45634563 * @param int $post_id The ID in the database table for the $post
    45644564 * @param object $post Object type containing the post information
    45654565 */
    4566 function _save_post_hook($post_id, $post) {
    4567         clean_post_cache($post_id, $post->post_type);
     4566function _save_post_hook( $post_id, $post ) {
     4567        clean_post_cache( $post );
    45684568}
    45694569
    45704570/**
  • wp-includes/deprecated.php

     
    31503150function clean_page_cache( $id ) {
    31513151        _deprecated_function( __FUNCTION__, 3.4, 'clean_post_cache()' );
    31523152
    3153         clean_post_cache( $id, 'page' );
     3153        clean_post_cache( $id );
    31543154}
  • wp-admin/includes/class-wp-posts-list-table.php

     
    360360                                if ( $page->post_parent == $page->ID ) {
    361361                                        $page->post_parent = 0;
    362362                                        $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
    363                                         clean_post_cache( $page->ID, $page->post_type );
     363                                        clean_post_cache( $page );
    364364                                }
    365365
    366366                                if ( 0 == $page->post_parent )