Skip to content

Commit

Permalink
Merge pull request #468 from pfefferle/fse-imporvements
Browse files Browse the repository at this point in the history
This PR would work on both classic and fse themes
  • Loading branch information
pfefferle authored May 13, 2024
2 parents 585fbcf + f570db0 commit 69c044e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
49 changes: 35 additions & 14 deletions includes/class-comment-walker.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function init() {

// Remove Webmention types from the Comment Template Query
if ( separate_webmentions_from_comments() ) {
add_filter( 'comments_template_query_args', array( static::class, 'filter_comments_query_args' ) );
add_action( 'pre_get_comments', array( static::class, 'comment_query' ) );

add_action( 'comment_form_before', array( static::class, 'show_separated_reactions' ) );
add_action( 'comment_form_comments_closed', array( static::class, 'show_separated_reactions' ) );
Expand All @@ -37,19 +37,6 @@ public static function filter_comment_args( $args ) {
return $args;
}

/**
* Filter the comment template query arguments to exclude Webmention comment types
*
* @param array $args an array of arguments for displaying comments
*
* @return array the filtered array
*/
public static function filter_comments_query_args( $args ) {
$args['type__not_in'] = get_webmention_comment_type_names();

return $args;
}

/**
* Show Facepile section
*/
Expand Down Expand Up @@ -285,4 +272,38 @@ protected function html5_comment( $comment, $depth, $args ) {
</article><!-- .comment-body -->
<?php
}

/**
* Excludes bookmarks, likes and reposts from comment queries.
*
* @author Jan Boddez
*
* @see https://github.com/janboddez/indieblocks/blob/a2d59de358031056a649ee47a1332ce9e39d4ce2/includes/functions.php#L423-L432
*
* @param WP_Comment_Query $query Comment count.
*/
public static function comment_query( $query ) {
if ( is_admin() ) {
return;
}

if ( ! is_singular() ) {
return;
}

if ( ! empty( $query->query_vars['meta_query'] ) ) {
$query = current( $query->query_vars['meta_query'] );

if ( ! empty( $query['key'] ) && 'protocol' === $query['key'] ) {
return;
}
}

if ( isset( $query->query_vars['count'] ) && true === $query->query_vars['count'] ) {
return;
}

// Exclude likes and reposts by the Webmention plugin.
$query->query_vars['type__not_in'] = get_webmention_comment_type_names();
}
}
30 changes: 18 additions & 12 deletions templates/webmention-comments.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<?php
$mentions = get_comments(
array(
'post_id' => get_the_ID(),
'type__in' => get_webmention_comment_type_names(),
'status' => 'approve',
'post_id' => get_the_ID(),
'type__in' => get_webmention_comment_type_names(),
'meta_query' => array(
array(
'key' => 'protocol',
'compare' => 'EXISTS',
),
),
'status' => 'approve',
)
);

$grouped_mentions = separate_comments( $mentions );
$fold_limit = get_option( 'webmention_facepile_fold_limit', 0 );
$fold_limit = get_option( 'webmention_facepile_fold_limit', 0 );

do_action( 'webmention_before_reaction_list' );

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

<?php if( ( $fold_limit > 0 ) && $fold_limit < count( $mentions ) ) {
<?php
if ( ( $fold_limit > 0 ) && $fold_limit < count( $mentions ) ) {
$overflow = array_slice( $mentions, $fold_limit );
$show = array_slice( $mentions, 0, $fold_limit );
?>
$show = array_slice( $mentions, 0, $fold_limit );
?>
<details class="webmention-facepile">
<summary>
<?php
wp_list_comments(
<?php
wp_list_comments(
array(
'avatar_only' => true,
'avatar_size' => 64,
Expand All @@ -38,7 +45,7 @@
?>
</summary>
<?php
wp_list_comments(
wp_list_comments(
array(
'avatar_only' => true,
'avatar_size' => 64,
Expand All @@ -47,13 +54,12 @@
);
?>
</details>
<?php
<?php
} else {
wp_list_comments(
array(
'avatar_only' => true,
'avatar_size' => 64,

),
$mentions
);
Expand Down

0 comments on commit 69c044e

Please sign in to comment.