Skip to content

Conversation

@jeherve
Copy link
Member

@jeherve jeherve commented Feb 10, 2026

Fixes #451

Caution

This is just a proof of concept, nothing more for now. It has now been fully tested or vetted.

Proposed changes:

  • Add a new Fediverse Stats dashboard widget that displays key ActivityPub metrics: followers, following (when enabled), likes, reposts, and federated comments.
  • Each stat is shown as a card in a 2-column grid with a dashicon, label, and large formatted number (using number_format_i18n with the existing custom_large_numbers filter for K/M/B suffixes).
  • Include onboarding tips when a user has no followers yet — linking to the settings page and suggesting the Follow Me block for block themes.
  • Onboarding tips are filterable via activitypub_dashboard_widget_tips.
  • Remove the old profile/blog-profile dashboard widgets (replaced by this unified widget).
  • Responsive: switches to single-column layout on mobile.

See also #1736 for related discussion.

Screenshot 2026-02-10 at 21 49 15

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to the WordPress admin dashboard (wp-admin).
  • Verify a Fediverse Stats widget appears with cards for Followers, Likes, Reposts, and Comments (all showing 0 for a fresh install).
  • If the Following UI is enabled (activitypub_following_ui option set to 1), verify a Following card also appears.
  • With 0 followers, verify onboarding tips are displayed:
    • A link to the ActivityPub settings page.
    • If using a block theme, a suggestion to add the Follow Me block via the site editor.
  • Create a post, then simulate ActivityPub interactions (likes, reposts, comments with protocol = activitypub comment meta) and verify the counts update.
  • Verify numbers are properly formatted for the current locale.
  • Test on a narrow viewport (< 782px) to confirm the grid switches to single-column.
  • Verify the widget only shows for users with activitypub capability or manage_options.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Add a Fediverse Stats dashboard widget displaying followers, likes, reposts, and comment counts with onboarding tips for new users.

Copilot AI review requested due to automatic review settings February 10, 2026 21:02
@jeherve jeherve self-assigned this Feb 10, 2026
@jeherve jeherve requested a review from a team February 10, 2026 21:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a unified Fediverse Stats dashboard widget in wp-admin, replacing the previous profile-related dashboard widgets, and introducing basic PHPUnit coverage for the new stats computations.

Changes:

  • Introduces Activitypub\WP_Admin\Dashboard_Widget to register/render a “Fediverse Stats” dashboard widget with onboarding tips.
  • Adds admin CSS for the widget layout (2-column grid, responsive to 1-column on small viewports).
  • Adds PHPUnit tests for stats counting and widget registration; removes legacy profile/blog-profile dashboard widgets.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
includes/wp-admin/class-dashboard-widget.php New dashboard widget implementation: registration, stat aggregation, and onboarding tips
includes/wp-admin/class-admin.php Hooks the new widget init; removes old author/blog profile dashboard widgets
assets/css/activitypub-admin.css Adds styles for the stats grid/cards and onboarding section + mobile breakpoint behavior
tests/phpunit/tests/includes/wp-admin/class-test-dashboard-widget.php Adds unit tests for Dashboard_Widget::get_stats() and widget registration
.github/changelog/add-dashboard-stats-widget Changelog entry for the new widget feature

Comment on lines +98 to +109
$following_count = 0;
if ( '1' === \get_option( 'activitypub_following_ui', '0' ) ) {
$following_count = (int) Following::count( $user_id );
}

return array(
'followers' => (int) count_followers( $user_id ),
'following' => $following_count,
'likes' => (int) self::count_interactions_by_type( 'like', $post_author_query ),
'reposts' => (int) self::count_interactions_by_type( 'repost', $post_author_query ),
'comments' => (int) self::count_interactions_by_type( 'comment', $post_author_query ),
);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_stats() computes likes/reposts/comments via three separate get_comments() count queries, each with a meta_query on protocol. On large sites this can make the dashboard noticeably slower. Consider reducing this to a single aggregated query (e.g., one comment query grouped by comment_type) and/or caching the computed counts (transient/object cache) and invalidating on new ActivityPub interactions.

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +119
public function test_get_stats_counts_likes() {
$user_id = self::factory()->user->create( array( 'role' => 'author' ) );
$user = new \WP_User( $user_id );
$user->add_cap( 'activitypub' );
\wp_set_current_user( $user_id );

$post_id = self::factory()->post->create( array( 'post_author' => $user_id ) );

$comment_id = self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_type' => 'like',
'comment_approved' => 1,
)
);
\add_comment_meta( $comment_id, 'protocol', 'activitypub' );

$stats = Dashboard_Widget::get_stats( $user_id );

$this->assertSame( 1, $stats['likes'] );
}

/**
* Test that get_stats counts reposts correctly.
*
* @covers ::get_stats
*/
public function test_get_stats_counts_reposts() {
$user_id = self::factory()->user->create( array( 'role' => 'author' ) );
$user = new \WP_User( $user_id );
$user->add_cap( 'activitypub' );
\wp_set_current_user( $user_id );

$post_id = self::factory()->post->create( array( 'post_author' => $user_id ) );

$comment_id = self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_type' => 'repost',
'comment_approved' => 1,
)
);
\add_comment_meta( $comment_id, 'protocol', 'activitypub' );

$stats = Dashboard_Widget::get_stats( $user_id );

$this->assertSame( 1, $stats['reposts'] );
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current tests validate counting when there's only one author's content. Since count_interactions_by_type() attempts to scope counts via post_author, add a test that creates interactions on posts by multiple authors and asserts get_stats( $user_id ) only counts interactions on that user's posts. This will catch regressions (or unsupported query vars) where the scoping is ignored and site-wide counts are shown.

Copilot uses AI. Check for mistakes.
@pfefferle
Copy link
Member

I already worked on something similar #2633

@jeherve jeherve closed this Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: add follower count to the ‘At a Glance’ dashboard widget

2 participants