[wp-trac] [WordPress Trac] #32366: wp_count_comments() is hardcoded into /wp-admin/menu.php and queries all comments every single page load within the admin area, regardless of if edt_posts is removed from top menu or not
WordPress Trac
noreply at wordpress.org
Fri May 27 17:45:46 UTC 2016
#32366: wp_count_comments() is hardcoded into /wp-admin/menu.php and queries all
comments every single page load within the admin area, regardless of if
edt_posts is removed from top menu or not
-----------------------------+------------------------------------------
Reporter: justindocanto | Owner:
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Future Release
Component: Comments | Version: 4.2
Severity: normal | Resolution:
Keywords: has-patch close | Focuses: administration, performance
-----------------------------+------------------------------------------
Changes (by rachelbaker):
* keywords: has-patch => has-patch close
Comment:
With the introduction of the `wp_count_comments` in #35060 you can skip
the comment count query from running. I don't think we need another
filter.
To skip the comment counts for all posts (including the admin_bar and
menu), a function like this should do the trick:
{{{#!php
<?php
add_filter( 'wp_count_comments', 'skip_comment_count_query', 10, 2 );
function skip_comment_count_query( $count, $post_id ) {
if ( 0 === $post_id ) {
$stats = array(
'approved' => 0,
'moderated' => 0,
'spam' => 0,
'trash' => 0,
'post-trashed' => 0,
'total_comments' => 0,
'all' => 0,
);
return (object) $stats;
}
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32366#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list