Skip to content

Commit 71faff1

Browse files
committed
Add Fediverse view to admin comment screen
Introduces a 'Fediverse' filter in the admin comment views, allowing users to view comments from hidden post types such as 'ap_post'. Updates comment query logic to support this new view and display only relevant comments when selected.
1 parent 19f34f0 commit 71faff1

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

includes/class-comment.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,17 @@ public static function comment_query( $query ) {
702702
return;
703703
}
704704

705-
// Do only exclude interactions of `ap_post` post type.
705+
// Handle admin comment queries.
706706
if ( \is_admin() ) {
707-
$query->query_vars['post_type'] = array_diff( \get_post_types_by_support( 'comments' ), self::hide_for() );
707+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
708+
if ( isset( $_GET['comment_status'] ) && 'federated' === $_GET['comment_status'] && empty( $query->query_vars['count'] ) ) {
709+
// Show only comments from hidden post types (Fediverse view).
710+
$query->query_vars['post_type'] = self::hide_for();
711+
$query->query_vars['status'] = 'all';
712+
} else {
713+
// Exclude comments from hidden post types.
714+
$query->query_vars['post_type'] = array_diff( \get_post_types_by_support( 'comments' ), self::hide_for() );
715+
}
708716
return;
709717
}
710718

includes/wp-admin/class-admin.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static function init() {
4545
\add_filter( 'manage_edit-comments_columns', array( static::class, 'manage_comment_columns' ) );
4646
\add_action( 'manage_comments_custom_column', array( static::class, 'manage_comments_custom_column' ), 9, 2 );
4747
\add_filter( 'admin_comment_types_dropdown', array( static::class, 'comment_types_dropdown' ) );
48+
\add_filter( 'views_edit-comments', array( static::class, 'comment_views' ) );
4849

4950
\add_filter( 'manage_posts_columns', array( static::class, 'manage_post_columns' ), 10, 2 );
5051
\add_action( 'manage_posts_custom_column', array( self::class, 'manage_posts_custom_column' ), 10, 2 );
@@ -547,6 +548,41 @@ public static function comment_types_dropdown( $types ) {
547548
return $types;
548549
}
549550

551+
/**
552+
* Add "Fediverse" view to the comment views.
553+
*
554+
* This allows users to see comments from hidden post types like ap_post.
555+
*
556+
* @param array $views The existing comment views.
557+
*
558+
* @return array The extended comment views.
559+
*/
560+
public static function comment_views( $views ) {
561+
$post_types = Comment::hide_for();
562+
563+
if ( empty( $post_types ) ) {
564+
return $views;
565+
}
566+
567+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
568+
$is_fediverse_view = isset( $_GET['comment_status'] ) && 'federated' === $_GET['comment_status'];
569+
$current = $is_fediverse_view ? 'current' : '';
570+
571+
// Remove "current" class from "All" when in Fediverse view.
572+
if ( $is_fediverse_view && isset( $views['all'] ) ) {
573+
$views['all'] = \str_replace( 'current', '', $views['all'] );
574+
}
575+
576+
$views['federated'] = \sprintf(
577+
'<a href="%s" class="%s">%s</a>',
578+
\esc_url( \admin_url( 'edit-comments.php?comment_status=federated' ) ),
579+
\esc_attr( $current ),
580+
\esc_html__( 'Fediverse', 'activitypub' )
581+
);
582+
583+
return $views;
584+
}
585+
550586
/**
551587
* Return the results for the activitypub column.
552588
*

0 commit comments

Comments
 (0)