-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Comments: Add filter for comment types excluded from queries by default #12310
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
Open
adamsilverstein
wants to merge
23
commits into
WordPress:trunk
Choose a base branch
from
adamsilverstein:feature/65537-excluded-comment-types-filter
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b7cb7fc
Comments: Add filter for comment types excluded from queries by default
adamsilverstein 4b57b1a
Apply suggestion from @adamsilverstein
adamsilverstein 9e9fb0b
Apply suggestion from @adamsilverstein
adamsilverstein 6e67226
Apply suggestion from @adamsilverstein
adamsilverstein 237d916
Apply suggestion from @adamsilverstein
adamsilverstein bb238e9
Comments: Clarify the default_excluded_comment_types filter is not ac…
adamsilverstein 1a4bf12
Comments: Feed default_excluded_comment_types into the comment counter.
adamsilverstein 2f75e55
Comments: Honor default_excluded_comment_types in pending counts.
adamsilverstein e656cbd
Comments: Extract wp_get_default_excluded_comment_types().
adamsilverstein 9355bd4
Merge branch 'trunk' into feature/65537-excluded-comment-types-filter
adamsilverstein e0d3cf9
Comments: Treat aliased type requests as explicit against excluded ty…
adamsilverstein 4f69762
Comments: Keep a comment type named '0' in the excluded types list.
adamsilverstein 0ded145
Comments: Drop the unsupported "feeds" claim from the filter docblock.
adamsilverstein c082ed3
Comments: Apply the excluded types filter in the comments list table.
adamsilverstein bebcf94
Merge branch 'trunk' into feature/65537-excluded-comment-types-filter
adamsilverstein 91e2876
Merge branch 'trunk' into feature/65537-excluded-comment-types-filter
adamsilverstein b3fc3ef
Comments: Drop non-scalar values from the excluded comment types filter.
adamsilverstein e658376
Potential fix for pull request finding
adamsilverstein 3e371d0
Merge branch 'trunk' into feature/65537-excluded-comment-types-filter
adamsilverstein 3d507a5
Merge branch 'trunk' into feature/65537-excluded-comment-types-filter
adamsilverstein 29af50b
Merge branch 'trunk' into feature/65537-excluded-comment-types-filter
adamsilverstein e0e1c5e
Comments: Let the list table show an explicitly requested excluded type.
adamsilverstein 106def5
Merge branch 'trunk' into feature/65537-excluded-comment-types-filter
adamsilverstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
137 changes: 137 additions & 0 deletions
137
tests/phpunit/tests/admin/includes/comment/GetPendingCommentsNum_Test.php
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @group admin | ||
| * @group comment | ||
| * | ||
| * @covers ::get_pending_comments_num | ||
| */ | ||
| class Admin_Includes_Comment_GetPendingCommentsNum_Test extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Creates a pending (unapproved) comment of a given type on a post. | ||
| * | ||
| * @param int $post_id Post to attach the comment to. | ||
| * @param string $comment_type Comment type slug. | ||
| * @return int The new comment ID. | ||
| */ | ||
| private function make_pending( $post_id, $comment_type = 'comment' ) { | ||
| return self::factory()->comment->create( | ||
| array( | ||
| 'comment_post_ID' => $post_id, | ||
| 'comment_type' => $comment_type, | ||
| 'comment_approved' => '0', | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 65537 | ||
| */ | ||
| public function test_counts_only_pending_comments() { | ||
| $post_id = self::factory()->post->create(); | ||
| $this->make_pending( $post_id ); | ||
| self::factory()->comment->create( | ||
| array( | ||
| 'comment_post_ID' => $post_id, | ||
| 'comment_approved' => '1', | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertSame( 1, get_pending_comments_num( $post_id ) ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 65537 | ||
| */ | ||
| public function test_excludes_note_type_by_default() { | ||
| $post_id = self::factory()->post->create(); | ||
| $this->make_pending( $post_id ); | ||
| $this->make_pending( $post_id, 'note' ); | ||
|
|
||
| $this->assertSame( 1, get_pending_comments_num( $post_id ) ); | ||
| } | ||
|
|
||
| /** | ||
| * A type added to the excluded set must drop out of the pending count. | ||
| * | ||
| * @ticket 65537 | ||
| */ | ||
| public function test_excludes_a_filtered_type() { | ||
| $post_id = self::factory()->post->create(); | ||
| $this->make_pending( $post_id ); | ||
| $this->make_pending( $post_id, 'review' ); | ||
|
|
||
| // 'review' is counted by default. | ||
| $this->assertSame( 2, get_pending_comments_num( $post_id ) ); | ||
|
|
||
| $filter = static function ( $types ) { | ||
| $types[] = 'review'; | ||
| return $types; | ||
| }; | ||
| add_filter( 'default_excluded_comment_types', $filter ); | ||
| $num = get_pending_comments_num( $post_id ); | ||
| remove_filter( 'default_excluded_comment_types', $filter ); | ||
|
|
||
| $this->assertSame( 1, $num ); | ||
| } | ||
|
|
||
| /** | ||
| * The exclusion is filter-driven, not a hard-coded 'note' literal. | ||
| * | ||
| * @ticket 65537 | ||
| */ | ||
| public function test_emptying_filter_counts_note_type() { | ||
| $post_id = self::factory()->post->create(); | ||
| $this->make_pending( $post_id, 'note' ); | ||
|
|
||
| $this->assertSame( 0, get_pending_comments_num( $post_id ) ); | ||
|
|
||
| add_filter( 'default_excluded_comment_types', '__return_empty_array' ); | ||
| $num = get_pending_comments_num( $post_id ); | ||
| remove_filter( 'default_excluded_comment_types', '__return_empty_array' ); | ||
|
|
||
| $this->assertSame( 1, $num ); | ||
| } | ||
|
|
||
| /** | ||
| * A filter callback returning false degrades gracefully to no exclusions. | ||
| * | ||
| * Scalar returns are cast to an array and treated as a single excluded type; | ||
| * only values that normalize to an empty set disable the exclusions. | ||
| * | ||
| * @ticket 65537 | ||
| */ | ||
| public function test_false_filter_return_counts_all_types() { | ||
| $post_id = self::factory()->post->create(); | ||
| $this->make_pending( $post_id, 'note' ); | ||
|
|
||
| add_filter( 'default_excluded_comment_types', '__return_false' ); | ||
| $num = get_pending_comments_num( $post_id ); | ||
| remove_filter( 'default_excluded_comment_types', '__return_false' ); | ||
|
|
||
| $this->assertSame( 1, $num ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 65537 | ||
| */ | ||
| public function test_array_input_returns_counts_keyed_by_post() { | ||
| $post_a = self::factory()->post->create(); | ||
| $post_b = self::factory()->post->create(); | ||
| $this->make_pending( $post_a ); | ||
| $this->make_pending( $post_a, 'note' ); | ||
| $this->make_pending( $post_b ); | ||
| $this->make_pending( $post_b ); | ||
|
|
||
| $counts = get_pending_comments_num( array( $post_a, $post_b ) ); | ||
|
|
||
| $this->assertSame( | ||
| array( | ||
| $post_a => 1, | ||
| $post_b => 2, | ||
| ), | ||
| $counts | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Good catch, fixed in e0e1c5e.
I didn't drop
type__not_inentirely though - the list table still has to force the exclusions for atype=allrequest.WP_Comment_Queryskips its default exclusions when 'all' is requested, and there is an existing test (test_comments_list_table_does_not_show_note_comment_type, added for #64198/#64474) asserting notes stay hidden onedit-comments.php?comment_type=all. Removing the arg outright regresses that.Instead the requested type is now subtracted from the exclusion list before the query runs, with the 'comment'/'comments'/'pings' aliases expanded the same way
WP_Comment_Queryexpands them:The 'note' type is still stripped from the request a few lines above, so that one remains unlistable in the admin regardless.
Added two tests in
tests/phpunit/tests/admin/wpCommentsListTable.php: a filtered-in 'private' type stays hidden for both an empty and anallrequest, and it is listed when explicitly selected. The second one fails against the old code (0 items) and passes now.