-
Notifications
You must be signed in to change notification settings - Fork 83
Comments: always exclude comments on ap_post from queries #2736
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
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
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_postinteractions
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.
3849ee8 to
29efd5d
Compare
Co-authored-by: Copilot <[email protected]>
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
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() ); |
Copilot
AI
Jan 8, 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.
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.
Co-authored-by: Copilot <[email protected]>
|
@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. |
|
Yes, it could interfere with the general frontend comment handling. |
|
@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? |
|
@jeherve makes sense! do you want me to take over or do you want to give it a try!? |
|
If you don't mind, I'd be happy to leave that one to you :) |
|
No problem! Let's close this then! |
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:
Testing instructions:
add_filter( 'activitypub_hide_comments_for', '__return_empty_array' );Changelog entry
Changelog Entry Details
Significance
Type
Message