Filter custom comment type from Manage Comments & Dash Widgets

I use comments with a custom comment type in my plugin to notify users of various events created by the plugin.

The problem is I don’t want these cluttering up the standard comments so I need to filter out those custom comments from the manage comments screen as well as the recent comments dashboard widget.

Read More

Does anyone have any ideas on how to do this?

Related posts

Leave a Reply

1 comment

  1. Doh, looks like the answer was staring me in the face.

    add_filter( 'comments_clauses', 'myPlugin_exclude_custom_comments', 10, 1);
    function myPlugin_exclude_custom_comments( $clauses ) {
    
        // Hide all those comments which aren't of type system_message
        $clauses['where'] .= ' AND comment_type != "system_message"';   
    
        return $clauses;
    }
    

    What this does is edit all comment queries to find comments that don’t have a type of system_message

    Hope this helps someone 🙂