diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 4a27fedb32..4c3b9faa48 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -500,17 +500,21 @@ function wp_update_comment_count($post_id) { $post_id = (int) $post_id; if ( !$post_id ) return false; - $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'"); - $wpdb->query("UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$post_id'"); - $comment_count_cache[$post_id] = $count; + if ( !$post = get_post($post_id) ) + return false; + + $old = (int) $post->comment_count; + $new = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'"); + $wpdb->query("UPDATE $wpdb->posts SET comment_count = '$new' WHERE ID = '$post_id'"); + $comment_count_cache[$post_id] = $new; - $post = get_post($post_id); if ( 'page' == $post->post_type ) clean_page_cache( $post_id ); else clean_post_cache( $post_id ); - do_action('edit_post', $post_id); + do_action('wp_update_comment_count', $post_id, $new, $old); + do_action('edit_post', $post_id, $post); return true; } @@ -816,4 +820,4 @@ function update_comment_cache($comments) { wp_cache_add($comment->comment_ID, $comment, 'comment'); } -?> \ No newline at end of file +?>