Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davemac/8480f799a03c8c110201 to your computer and use it in GitHub Desktop.
Save davemac/8480f799a03c8c110201 to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: Remove crazy counts slowing down my dashboard
* Plugin URI: https://pmgarman.me
* Description: Those comment counts are such a pain when you have a lot of comments
* Author: Patrick Garman
* Author URI: https://pmgarman.me
* Version: 1.0.0
* License: GPLv2
*/
// Remove unmoderated comment counts from the admin menu
function pmgarman_unmoderated_comment_counts( $stats, $post_id ) {
global $wpdb;
if ( 0 === $post_id ) {
$stats = json_decode( json_encode( array(
'moderated' => 0,
'approved' => 0,
'post-trashed' => 0,
'trash' => 0,
'total_comments' => 0
) ) );
}
return $stats;
}
add_filter( 'wp_count_comments', 'pmgarman_unmoderated_comment_counts', 10, 2 );
// If running WooCommerce, remove their filter so that nothing funky goes down
remove_filter( 'wp_count_comments', array( 'WC_Comments', 'wp_count_comments' ), 10 );
// Order counts in the admin menu can be removed once this filter is merged into WooCommerce
// https://github.com/woothemes/woocommerce/pull/9820
add_filter( 'woocommerce_include_order_count_in_menu', '__return_false' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment