Ticket #19690: 19690.21.diff

File 19690.21.diff, 4.1 KB (added by leewillis77, 14 months ago)

Patch to resolve issues that duck_ raised.

  • wp-includes/comment.php

     
    15831583        $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) ); 
    15841584        $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) ); 
    15851585 
    1586         if ( 'page' == $post->post_type ) 
    1587                 clean_page_cache( $post_id ); 
    1588         else 
    1589                 clean_post_cache( $post_id ); 
     1586        clean_post_cache( $post_id, $post->post_type ); 
    15901587 
    15911588        do_action('wp_update_comment_count', $post_id, $new, $old); 
    15921589        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         if ( 'page' == $post_type ) 
    1365                 clean_page_cache($post_id); 
    1366         else 
    1367                 clean_post_cache($post_id); 
     1364        clean_post_cache($post_id, $post_type); 
    13681365 
    13691366        return $return; 
    13701367} 
     
    20562053        $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) ); 
    20572054        do_action( 'deleted_post', $postid ); 
    20582055 
    2059         if ( 'page' == $post->post_type ) { 
    2060                 clean_page_cache($postid); 
    2061         } else { 
    2062                 clean_post_cache($postid); 
    2063         } 
     2056        clean_post_cache($postid, $post->post_type); 
    20642057 
    20652058        if ( is_post_type_hierarchical( $post->post_type ) ) { 
    20662059                foreach ( (array) $children as $child ) 
    2067                         clean_post_cache( $child->ID ); 
     2060                        clean_post_cache( $child->ID, $child->post_type ); 
    20682061        } 
    20692062 
    20702063        wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); 
     
    26432636 
    26442637        $current_guid = get_post_field( 'guid', $post_ID ); 
    26452638 
    2646         if ( 'page' == $data['post_type'] ) 
    2647                 clean_page_cache($post_ID); 
    2648         else 
    2649                 clean_post_cache($post_ID); 
     2639        clean_post_cache($post_ID, $data['post_type']); 
    26502640 
    26512641        // Set GUID 
    26522642        if ( !$update && '' == $current_guid ) 
     
    37513741        if ( $file ) 
    37523742                update_attached_file( $post_ID, $file ); 
    37533743 
    3754         clean_post_cache($post_ID); 
     3744        clean_post_cache($post_ID, $post_type); 
    37553745 
    37563746        if ( ! empty( $context ) ) 
    37573747                add_post_meta( $post_ID, '_wp_attachment_context', $context, true ); 
     
    38643854        if ( ! empty($file) ) 
    38653855                @ unlink($file); 
    38663856 
    3867         clean_post_cache($post_id); 
     3857        clean_post_cache($post_id, $post->post_type); 
    38683858 
    38693859        return $post; 
    38703860} 
     
    43484338 * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any). 
    43494339 * 
    43504340 * @param int $id The Post ID in the cache to clean 
     4341 * @param string $post_type The post_type of the post. Defaults to "post" 
    43514342 */ 
    4352 function clean_post_cache($id) { 
     4343function clean_post_cache($id, $post_type = 'post') { 
    43534344        global $_wp_suspend_cache_invalidation, $wpdb; 
    43544345 
    43554346        if ( !empty($_wp_suspend_cache_invalidation) ) 
     
    43604351        if ( 0 === $id ) 
    43614352                return; 
    43624353 
    4363         $post = get_post( $id ); 
    4364  
    43654354        wp_cache_delete($id, 'posts'); 
    43664355        wp_cache_delete($id, 'post_meta'); 
    43674356 
    4368         clean_object_term_cache( $id, $post->post_type ); 
     4357        clean_object_term_cache( $id, $post_type ); 
    43694358 
    43704359        wp_cache_delete( 'wp_get_archives', 'general' ); 
    43714360 
     
    43764365                        // Loop detection 
    43774366                        if ( $cid == $id ) 
    43784367                                continue; 
    4379                         clean_post_cache( $cid ); 
     4368                        clean_post_cache( $cid, $cid->post_type ); 
    43804369                } 
    43814370        } 
    43824371 
     
    44144403 * @param int $id Page ID to clean 
    44154404 */ 
    44164405function clean_page_cache($id) { 
    4417         clean_post_cache($id); 
     4406        clean_post_cache($id, 'page'); 
    44184407 
    44194408        wp_cache_delete( 'all_page_ids', 'posts' ); 
    44204409        wp_cache_delete( 'get_pages', 'posts' ); 
     
    46294618 * @param object $post Object type containing the post information 
    46304619 */ 
    46314620function _save_post_hook($post_id, $post) { 
    4632         if ( $post->post_type == 'page' ) { 
    4633                 clean_page_cache($post_id); 
    4634         } else { 
    4635                 clean_post_cache($post_id); 
    4636         } 
     4621        clean_post_cache($post_id, $post->post_type); 
    46374622} 
    46384623 
    46394624/** 
     
    53615346 
    53625347                update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); 
    53635348        } 
    5364 } 
    5365  No newline at end of file 
     5349}