Skip to content

Commit 98e375a

Browse files
committed
this PR would work on both classic and fse themes
1 parent 381b3f0 commit 98e375a

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

includes/class-comment-walker.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function init() {
1717

1818
// Remove Webmention types from the Comment Template Query
1919
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' ) );
2121

2222
add_action( 'comment_form_before', array( static::class, 'show_separated_reactions' ) );
2323
add_action( 'comment_form_comments_closed', array( static::class, 'show_separated_reactions' ) );
@@ -37,19 +37,6 @@ public static function filter_comment_args( $args ) {
3737
return $args;
3838
}
3939

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-
5340
/**
5441
* Show Facepile section
5542
*/
@@ -285,4 +272,32 @@ protected function html5_comment( $comment, $depth, $args ) {
285272
</article><!-- .comment-body -->
286273
<?php
287274
}
275+
276+
/**
277+
* Excludes bookmarks, likes and reposts from comment queries.
278+
*
279+
* @todo: Use some kind of "comment taxonomy" instead?
280+
*
281+
* @param WP_Comment_Query $query Comment count.
282+
*/
283+
public static function comment_query( $query ) {
284+
if ( is_admin() ) {
285+
return;
286+
}
287+
288+
if ( ! is_singular() ) {
289+
return;
290+
}
291+
292+
if ( ! empty( $query->query_vars['type__in'] ) ) {
293+
return;
294+
}
295+
296+
if ( isset( $query->query_vars['count'] ) && true === $query->query_vars['count'] ) {
297+
return;
298+
}
299+
300+
// Exclude likes and reposts by the Webmention plugin.
301+
$query->query_vars['type__not_in'] = get_webmention_comment_type_names();
302+
}
288303
}

templates/webmention-comments.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
<ul class="reaction-list reaction-list--<?php echo esc_attr( $mention_type ); ?>">
2222
<h2><?php echo get_webmention_comment_type_attr( $mention_type, 'label' ); ?></h2>
2323

24-
<?php if( ( $fold_limit > 0 ) && $fold_limit < count( $mentions ) ) {
24+
<?php if ( ( $fold_limit > 0 ) && $fold_limit < count( $mentions ) ) {
2525
$overflow = array_slice( $mentions, $fold_limit );
2626
$show = array_slice( $mentions, 0, $fold_limit );
2727
?>
2828
<details class="webmention-facepile">
2929
<summary>
30-
<?php
31-
wp_list_comments(
30+
<?php
31+
wp_list_comments(
3232
array(
3333
'avatar_only' => true,
3434
'avatar_size' => 64,
@@ -38,7 +38,7 @@
3838
?>
3939
</summary>
4040
<?php
41-
wp_list_comments(
41+
wp_list_comments(
4242
array(
4343
'avatar_only' => true,
4444
'avatar_size' => 64,

0 commit comments

Comments
 (0)