Repository navigation
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
huzaifaalmesbah
left a comment
There was a problem hiding this comment.
Thanks for working on this, @irozum! I really appreciate you covering both sides of the suppress_filters default in get_posts(), the suppressed default and the explicit opt-out; the get_posts() tests didn't touch it before.
One note on the ticket: #7326 was closed as fixed in 2.6.2, so it can't take new commits. Coverage additions without a ticket of their own usually go under the release's test umbrella ticket, which for 7.2 is #65819. Would you be open to updating the Trac ticket: link in the description to that one?
I left one small note inline as well.
AI Review: Opus 5.5
| add_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) ); | ||
| get_posts(); | ||
| remove_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) ); | ||
|
|
||
| $this->assertFalse( $this->posts_where_filter_fired ); |
There was a problem hiding this comment.
MockAction can do the counting here, which would let the extra property and callback go, and the remove_filter() isn't needed since hooks are restored in tear_down().
| add_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) ); | |
| get_posts(); | |
| remove_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) ); | |
| $this->assertFalse( $this->posts_where_filter_fired ); | |
| $filter = new MockAction(); | |
| add_filter( 'posts_where', array( $filter, 'filter' ) ); | |
| get_posts(); | |
| $this->assertSame( 0, $filter->get_call_count() ); |
The second test could do the same with assertSame( 1, ... ). What do you think?
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified in the test-only regression coverage for get_posts() filter suppression.
No open issues 🎉
What changed in this PR
Adds regression coverage for get_posts() filter suppression, following up on the fix for ticket #7326. This is a test-only change with no production code modifications.
Changes:
- Verifies that
posts_wherefilters are suppressed by default. - Verifies that setting
suppress_filterstofalseallows the filter to run.
| File | Description |
|---|---|
tests/phpunit/tests/post/getPosts.php |
Adds two filter-suppression tests and a shared callback that records whether the filter ran. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
Reviewed the changed assertions against existing coverage and production behavior. Randomized single-site and multisite runs passed 60 tests / 195 assertions with three seeds; PHPCS passes. Both targeted regression mutations fail as intended. No blockers. The suggested MockAction simplification and removal of redundant local hook cleanup are optional; they do not affect the regression coverage.
AI review · gpt-6
Verify that `get_posts()` suppresses `posts_where` filters by default and honors an explicit `suppress_filters` value of `false`. Developed in: #14015 Props irozum, huzaifaalmesbah. See #65819, #7326. git-svn-id: https://develop.svn.wordpress.org/trunk@65101 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #14015 landed in https://core.trac.wordpress.org/changeset/65101 |
Verify that `get_posts()` suppresses `posts_where` filters by default and honors an explicit `suppress_filters` value of `false`. Developed in: WordPress/wordpress-develop#14015 Props irozum, huzaifaalmesbah. See #65819, #7326. Built from https://develop.svn.wordpress.org/trunk@65101 git-svn-id: http://core.svn.wordpress.org/trunk@64251 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This is a test-only PR adding PHPUnit coverage for
get_posts()'ssuppress_filtersdefault, with no production code changes.What's covered:
get_posts()insrc/wp-includes/post.phpdefaultssuppress_filterstotrue, unlikeWP_Query's own default offalse. This was the fix for this ticket ([8795]) — before it,get_posts()queries were silently mutated byposts_where/posts_join-style filters that plugins register for the main query, which is what the original bug report described. That default is still present verbatim in trunk but had no direct test guarding it.Tests added in
tests/phpunit/tests/post/getPosts.php:test_should_suppress_posts_where_filter_by_default()— registers aposts_wherefilter, callsget_posts()with nosuppress_filtersargument, and asserts the filter never fires.test_suppress_filters_false_should_apply_posts_where_filter()— same filter, but callsget_posts( array( 'suppress_filters' => false ) )and asserts the filter does fire, proving the flag is actually wired through to the underlyingWP_Queryrather than just documented.Why these cases: together they pin down both sides of the behavior the ticket's fix introduced — the suppressed-by-default case (the actual bug fix) and the explicit opt-out (so a future regression that silently drops the override can't hide behind the default-only test passing). I verified each test is meaningful by temporarily flipping the
suppress_filtersdefault tofalseinsrc/wp-includes/post.php: the default-suppression test failed as expected, and reverting restored a green run. The wholeTests_Post_GetPostsclass (60 tests) and--group 7326pass, along withcomposer lint:errorsandcomposer phpstan.Tests are a follow-up to the changeset that fixed this ticket: Follow-up to [8795].
Trac ticket: https://core.trac.wordpress.org/ticket/7326
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Ticket selection/triage, writing the test cases, and verifying them (including the red/green check against a deliberately reverted fix). I reviewed the diff, ran the full test/lint/typecheck gate myself, and take responsibility for the change.