@@ -17,7 +17,7 @@ public static function init() {
17
17
18
18
// Remove Webmention types from the Comment Template Query
19
19
if ( separate_webmentions_from_comments () ) {
20
- add_filter ( 'comments_template_query_args ' , array ( static ::class, 'filter_comments_query_args ' ) );
20
+ add_action ( 'pre_get_comments ' , array ( static ::class, 'comment_query ' ) );
21
21
22
22
add_action ( 'comment_form_before ' , array ( static ::class, 'show_separated_reactions ' ) );
23
23
add_action ( 'comment_form_comments_closed ' , array ( static ::class, 'show_separated_reactions ' ) );
@@ -37,19 +37,6 @@ public static function filter_comment_args( $args ) {
37
37
return $ args ;
38
38
}
39
39
40
- /**
41
- * Filter the comment template query arguments to exclude Webmention comment types
42
- *
43
- * @param array $args an array of arguments for displaying comments
44
- *
45
- * @return array the filtered array
46
- */
47
- public static function filter_comments_query_args ( $ args ) {
48
- $ args ['type__not_in ' ] = get_webmention_comment_type_names ();
49
-
50
- return $ args ;
51
- }
52
-
53
40
/**
54
41
* Show Facepile section
55
42
*/
@@ -285,4 +272,38 @@ protected function html5_comment( $comment, $depth, $args ) {
285
272
</article><!-- .comment-body -->
286
273
<?php
287
274
}
275
+
276
+ /**
277
+ * Excludes bookmarks, likes and reposts from comment queries.
278
+ *
279
+ * @author Jan Boddez
280
+ *
281
+ * @see https://github.com/janboddez/indieblocks/blob/a2d59de358031056a649ee47a1332ce9e39d4ce2/includes/functions.php#L423-L432
282
+ *
283
+ * @param WP_Comment_Query $query Comment count.
284
+ */
285
+ public static function comment_query ( $ query ) {
286
+ if ( is_admin () ) {
287
+ return ;
288
+ }
289
+
290
+ if ( ! is_singular () ) {
291
+ return ;
292
+ }
293
+
294
+ if ( ! empty ( $ query ->query_vars ['meta_query ' ] ) ) {
295
+ $ query = current ( $ query ->query_vars ['meta_query ' ] );
296
+
297
+ if ( ! empty ( $ query ['key ' ] ) && 'protocol ' === $ query ['key ' ] ) {
298
+ return ;
299
+ }
300
+ }
301
+
302
+ if ( isset ( $ query ->query_vars ['count ' ] ) && true === $ query ->query_vars ['count ' ] ) {
303
+ return ;
304
+ }
305
+
306
+ // Exclude likes and reposts by the Webmention plugin.
307
+ $ query ->query_vars ['type__not_in ' ] = get_webmention_comment_type_names ();
308
+ }
288
309
}
0 commit comments