Add hide_for method to Comment class#2662
Merged
Conversation
37a94b4 to
f80d3a5
Compare
This method returns post types whose comments should be hidden in the WordPress admin. Used for filtering comment queries and auto-approving comments on non-public post types like ap_post.
f80d3a5 to
0ccf3fe
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new get_non_public_post_types() helper method to the Comment class and refactors existing methods to use it. However, the refactoring introduces significant behavioral changes that break backward compatibility.
Key Changes:
- Adds
get_non_public_post_types()method that retrieves all WordPress post types withpublic => false - Refactors
comment_query()to always filter non-public post types instead of only whenactivitypub_create_postsoption is enabled - Refactors
pre_comment_approved()to auto-approve comments on any non-public post type instead of justap_postwhen the option is enabled
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| includes/class-comment.php | Adds new get_non_public_post_types() method and refactors comment_query() and pre_comment_approved() to use it, removing the Posts import and activitypub_create_posts option checks |
| tests/phpunit/tests/includes/class-test-comment.php | Adds basic unit test for the new method and imports Posts class |
| .github/changelog/add-get-non-public-post-types | Adds changelog entry for the new feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jeherve
reviewed
Dec 18, 2025
9ed7c81 to
249248b
Compare
This method returns post types whose comments should be hidden in the WordPress admin comments list.
249248b to
19f34f0
Compare
jeherve
previously approved these changes
Dec 18, 2025
Member
jeherve
left a comment
There was a problem hiding this comment.
This looks good and tests well for me. I like the addition of the filter, it should allow third-parties to hook into that logic if necessary.
73b75bb to
19f34f0
Compare
11 tasks
jeherve
approved these changes
Dec 18, 2025
jeherve
added a commit
that referenced
this pull request
Jan 8, 2026
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.
11 tasks
jeherve
added a commit
that referenced
this pull request
Jan 8, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes:
hide_for()method to theCommentclass that returns post types whose comments should be hidden in the WordPress admin.comment_query()andpre_comment_approved()methods to use the new helper method.activitypub_hide_comments_forfilter to customize which post types have hidden comments.Other information:
Testing instructions:
npm run env-test -- --filter=test_hide_forap_postis the only post type in the default listChangelog entry
Changelog entry added manually via
composer changelog:add.