WordPress.org

Make WordPress Core

Ticket #4740: 4740.diff

File 4740.diff, 1.3 KB (added by mdawaffe, 11 years ago)
  • wp-includes/comment.php

     
    500500        $post_id = (int) $post_id;
    501501        if ( !$post_id )
    502502                return false;
    503         $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'");
    504         $wpdb->query("UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$post_id'");
    505         $comment_count_cache[$post_id] = $count;
     503        if ( !$post = get_post($post_id) )
     504                return false;
    506505
    507         $post = get_post($post_id);
     506        $old = (int) $post->comment_count;
     507        $new = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'");
     508        $wpdb->query("UPDATE $wpdb->posts SET comment_count = '$new' WHERE ID = '$post_id'");
     509        $comment_count_cache[$post_id] = $new;
     510
    508511        if ( 'page' == $post->post_type )
    509512                clean_page_cache( $post_id );
    510513        else
    511514                clean_post_cache( $post_id );
    512515
    513         do_action('edit_post', $post_id);
     516        do_action('wp_update_comment_count', $post_id, $new, $old);
     517        do_action('edit_post', $post_id, $post);
    514518
    515519        return true;
    516520}
     
    816820                wp_cache_add($comment->comment_ID, $comment, 'comment');
    817821}
    818822
    819 ?>
    820  No newline at end of file
     823?>