Make WordPress Core

Ticket #36409: 36409.patch

File 36409.patch, 1.1 KB (added by sidati, 8 years ago)
  • comment.php

     
    21512151        $new = apply_filters( 'pre_wp_update_comment_count_now', null, $old, $post_id );
    21522152
    21532153        if ( is_null( $new ) ) {
    2154                 $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) );
     2154
     2155                $bad_parents = array();
     2156                $depth = $_depth = get_option('thread_comments_depth', 5);
     2157
     2158                while ($depth > 1) {
     2159                        $clause = ($_depth == $depth) ? " AND comment_approved != '1'" : null;
     2160                        $bad_parents += $wpdb->get_col("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = $post_id.$clause");
     2161                        $depth--;
     2162                }
     2163
     2164                $bad_parents = array_unique($bad_parents);
     2165                $bad_parents = implode(',', $bad_parents);
     2166
     2167                $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND comment_parent NOT IN ($bad_parents)", $post_id ) );
    21552168        } else {
    21562169                $new = (int) $new;
    21572170        }