Skip to content

Commit 69c044e

Browse files
authored
Merge pull request #468 from pfefferle/fse-imporvements
This PR would work on both classic and fse themes
2 parents 585fbcf + f570db0 commit 69c044e

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

includes/class-comment-walker.php

Lines changed: 35 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,38 @@ 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+
* @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+
}
288309
}

templates/webmention-comments.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<?php
22
$mentions = get_comments(
33
array(
4-
'post_id' => get_the_ID(),
5-
'type__in' => get_webmention_comment_type_names(),
6-
'status' => 'approve',
4+
'post_id' => get_the_ID(),
5+
'type__in' => get_webmention_comment_type_names(),
6+
'meta_query' => array(
7+
array(
8+
'key' => 'protocol',
9+
'compare' => 'EXISTS',
10+
),
11+
),
12+
'status' => 'approve',
713
)
814
);
915

1016
$grouped_mentions = separate_comments( $mentions );
11-
$fold_limit = get_option( 'webmention_facepile_fold_limit', 0 );
17+
$fold_limit = get_option( 'webmention_facepile_fold_limit', 0 );
1218

1319
do_action( 'webmention_before_reaction_list' );
1420

@@ -21,14 +27,15 @@
2127
<ul class="reaction-list reaction-list--<?php echo esc_attr( $mention_type ); ?>">
2228
<h2><?php echo get_webmention_comment_type_attr( $mention_type, 'label' ); ?></h2>
2329

24-
<?php if( ( $fold_limit > 0 ) && $fold_limit < count( $mentions ) ) {
30+
<?php
31+
if ( ( $fold_limit > 0 ) && $fold_limit < count( $mentions ) ) {
2532
$overflow = array_slice( $mentions, $fold_limit );
26-
$show = array_slice( $mentions, 0, $fold_limit );
27-
?>
33+
$show = array_slice( $mentions, 0, $fold_limit );
34+
?>
2835
<details class="webmention-facepile">
2936
<summary>
30-
<?php
31-
wp_list_comments(
37+
<?php
38+
wp_list_comments(
3239
array(
3340
'avatar_only' => true,
3441
'avatar_size' => 64,
@@ -38,7 +45,7 @@
3845
?>
3946
</summary>
4047
<?php
41-
wp_list_comments(
48+
wp_list_comments(
4249
array(
4350
'avatar_only' => true,
4451
'avatar_size' => 64,
@@ -47,13 +54,12 @@
4754
);
4855
?>
4956
</details>
50-
<?php
57+
<?php
5158
} else {
5259
wp_list_comments(
5360
array(
5461
'avatar_only' => true,
5562
'avatar_size' => 64,
56-
5763
),
5864
$mentions
5965
);

0 commit comments

Comments
 (0)