Skip to content

Conversation

@jeherve
Copy link
Member

@jeherve jeherve commented Jan 8, 2026

Fixes #2700

Proposed changes:

Follow-up to #2662 and #2667

Until now, we were only excluding the ap_post post type from comment queries happening within wp-admin. This is problematic because the admin bar menu item makes a wp_count_comments() call from anywhere on the site where the admin bar is displayed. That includes all frontend pages.

Since we do return early in the cases where we want those comments to appear, we should be able to always exclude them in other situations.

Other information:

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

Testing instructions:

  1. Start with a site where you started following other accounts, and where you've received both posts in your inbox, as well as comments on those posts.
  2. In a functionality plugin, set add_filter( 'activitypub_hide_comments_for', '__return_empty_array' );
  3. Load the comment management screen in wp-admin: you should now see the comments on some of the AP posts from the folks you follow.
  4. Unapprove 2 of those comments.
  5. Remove the custom code you added in step 2.
  6. Visit your site's home page.
  7. You should now see a counter indicating 2 pending comments in your WordPress admin bar.
  8. Checkout this branch.
  9. The counter should be set to 0.

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

Copilot AI review requested due to automatic review settings January 8, 2026 12:02
@jeherve jeherve self-assigned this Jan 8, 2026
@jeherve jeherve requested a review from a team January 8, 2026 12: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

This PR fixes an issue where comments on ap_post post types (posts from followed ActivityPub accounts) were being incorrectly counted in the WordPress admin bar comment counter. Previously, these comments were only excluded from queries within wp-admin, but wp_count_comments() is also called when rendering the admin bar on frontend pages.

Key Changes:

  • Moved the post type exclusion logic from inside an is_admin() check to always apply after other early return conditions
  • Added clarifying comments explaining the purpose of excluding ap_post interactions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
includes/class-comment.php Relocated the post type filter to exclude ap_post comments from all comment queries, not just admin queries
.github/changelog/fix-comment-count-ap-post-comments-admin-bar Added changelog entry documenting the fix
Comments suppressed due to low confidence (1)

includes/class-comment.php:708

  • There appears to be a logic issue with this change. The early return on line 706-708 prevents this filter from running on non-singular pages (like the homepage). However, according to the PR description, the problem being fixed is that wp_count_comments() is called from the admin bar on all frontend pages, including the homepage. With the current logic, line 723 will not execute when viewing the homepage, so the admin bar comment count issue won't be fixed on non-singular pages. Consider removing or modifying the early return condition on lines 705-708 to allow the post_type filter to apply in contexts where comment counts are being calculated.
		// Do not exclude likes and reposts on non-singular pages.
		if ( ! \is_singular() ) {
			return;
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Fixes #2700

Follow-up to #2662 and #2667

Until now, we were only excluding the ap_post post type from comment queries happening within wp-admin. This is problematic because the admin bar menu item makes a wp_count_comments() call from anywhere on the site where the admin bar is displayed. That includes all frontend pages.

Since we do return early in the cases where we want those comments to appear, we should be able to always exclude them in other situations.
@jeherve jeherve force-pushed the fix/comment-count-ap-post-comments-admin-bar branch from 3849ee8 to 29efd5d Compare January 8, 2026 12:06
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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* We do not want to display them on the comment management screen
* or in the admin bar.
*/
$query->query_vars['post_type'] = array_diff( \get_post_types_by_support( 'comments' ), self::hide_for() );
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

This change will cause the existing test test_ap_post_comments_shown_on_frontend to fail. The test expects ap_post comments to be visible on the frontend, but with this change, ap_post comments will now be excluded from all comment queries (except ActivityPub and REST requests), including frontend queries.

If the intent is to hide ap_post comments on the frontend as well, the test needs to be updated or removed. However, if ap_post comments should still be visible on the frontend, then this logic change needs to be reconsidered or additional conditional logic needs to be added.

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

@jeherve this PR seem to break the tests!?

@jeherve
Copy link
Member Author

jeherve commented Jan 8, 2026

@jeherve this PR seem to break the tests!?

Yes, I'm looking at that too. That's useful, it seems I'm breaking some expected behavior with that change. I'll see what I can find.

@pfefferle
Copy link
Member

Yes, it could interfere with the general frontend comment handling.

@jeherve
Copy link
Member Author

jeherve commented Jan 8, 2026

@pfefferle I don't see an easy way around that problem that won't impact the display of those comments elsewhere. I'm thinking we may be better off addressing #2735 directly instead. What do you think?

@pfefferle
Copy link
Member

@jeherve makes sense! do you want me to take over or do you want to give it a try!?

@jeherve
Copy link
Member Author

jeherve commented Jan 8, 2026

If you don't mind, I'd be happy to leave that one to you :)

@pfefferle
Copy link
Member

No problem! Let's close this then!

@pfefferle pfefferle closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comments on AP Posts bump count of comments to be moderated in admin bar

3 participants