@@ -25,6 +25,7 @@ public static function init() {
2525 \add_filter ( 'comment_class ' , array ( self ::class, 'comment_class ' ), 10 , 3 );
2626 \add_filter ( 'get_comment_link ' , array ( self ::class, 'remote_comment_link ' ), 11 , 3 );
2727 \add_action ( 'wp_enqueue_scripts ' , array ( self ::class, 'enqueue_scripts ' ) );
28+ \add_action ( 'pre_get_comments ' , array ( static ::class, 'comment_query ' ) );
2829
2930 \add_filter ( 'get_avatar_comment_types ' , array ( static ::class, 'get_avatar_comment_types ' ), 99 );
3031 }
@@ -592,4 +593,34 @@ public static function get_avatar_comment_types( $types ) {
592593
593594 return array_unique ( $ types );
594595 }
596+
597+ /**
598+ * Excludes likes and reposts from comment queries.
599+ *
600+ * @author Jan Boddez
601+ *
602+ * @see https://github.com/janboddez/indieblocks/blob/a2d59de358031056a649ee47a1332ce9e39d4ce2/includes/functions.php#L423-L432
603+ *
604+ * @param WP_Comment_Query $query Comment count.
605+ */
606+ public static function comment_query ( $ query ) {
607+ if ( ! $ query instanceof WP_Comment_Query ) {
608+ return ;
609+ }
610+
611+ if ( is_admin () || ! is_singular () ) {
612+ return ;
613+ }
614+
615+ if ( ! empty ( $ query ->query_vars ['type__in ' ] ) ) {
616+ return ;
617+ }
618+
619+ if ( isset ( $ query ->query_vars ['count ' ] ) && true === $ query ->query_vars ['count ' ] ) {
620+ return ;
621+ }
622+
623+ // Exclude likes and reposts by the Webmention plugin.
624+ $ query ->query_vars ['type__not_in ' ] = self ::get_comment_type_names ();
625+ }
595626}
0 commit comments