Make WordPress Core


Ignore:
Timestamp:
08/14/2007 03:08:44 AM (18 years ago)
Author:
ryan
Message:

wp_update_comment_count hook from mdawaffe. fixes #4740

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r5772 r5869  
    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;
    506 
    507     $post = get_post($post_id);
     503    if ( !$post = get_post($post_id) )
     504        return false;
     505
     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 );
     
    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;
Note: See TracChangeset for help on using the changeset viewer.