-
Notifications
You must be signed in to change notification settings - Fork 83
Add Fediverse Stats dashboard widget #2904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2-column grid of stat cards with large numbers, dashicons, responsive layout that stacks on mobile.
There was a problem hiding this 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_Widgetto 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 |
| $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 ), | ||
| ); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
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.
| 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'] ); | ||
| } |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
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.
|
I already worked on something similar #2633 |
Fixes #451
Caution
This is just a proof of concept, nothing more for now. It has now been fully tested or vetted.
Proposed changes:
number_format_i18nwith the existingcustom_large_numbersfilter for K/M/B suffixes).activitypub_dashboard_widget_tips.See also #1736 for related discussion.
Other information:
Testing instructions:
activitypub_following_uioption set to1), verify a Following card also appears.protocol=activitypubcomment meta) and verify the counts update.activitypubcapability ormanage_options.Changelog entry
Changelog Entry Details
Significance
Type
Message
Add a Fediverse Stats dashboard widget displaying followers, likes, reposts, and comment counts with onboarding tips for new users.