[wp-trac] [WordPress Trac] #19372: Don't call wp_count_comments() when we don't need to

WordPress Trac noreply at wordpress.org
Wed Nov 4 22:37:50 UTC 2015


#19372: Don't call wp_count_comments() when we don't need to
----------------------------+-----------------------------
 Reporter:  johnbillion     |       Owner:  wonderboymusic
     Type:  task (blessed)  |      Status:  assigned
 Priority:  normal          |   Milestone:  4.4
Component:  Comments        |     Version:  3.2
 Severity:  minor           |  Resolution:
 Keywords:  has-patch       |     Focuses:  performance
----------------------------+-----------------------------

Comment (by bordoni):

 Sorry to spam, but I taking a look at the code, and it's possible to fix
 the problem by adding a filter to `wp_count_comments`.
 Keep in mind that you might need to add a few more conditionals to make it
 work.
 {{{#!php
 <?php
 function filter_comments_counter_admin( $original, $post_id ){
     if ( is_admin() ) {
         return array(
                 'approved'            => 0,
                 'awaiting_moderation' => 0,
                 'spam'                => 0,
                 'trash'               => 0,
                 'post-trashed'        => 0,
                 'total_comments'      => 0,
                 'all'                 => 0,
         );
     }
 }
 add_filter( 'wp_count_comments' 'filter_comments_counter_admin' );
 }}}

 Or what @boonebgorges said would also work.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/19372#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list