Hooks: Fix resort_active_iterations() skipping next priority on self-removal #10949
Hooks: Fix resort_active_iterations() skipping next priority on self-removal #10949mrcasual wants to merge 1 commit intoWordPress:trunkfrom
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. |
…f-removal. When a callback removes itself during `do_action()`/`apply_filters()` and is the sole callback at its priority, `resort_active_iterations()` repositions the internal array pointer one position too far. The main loop's `next()` call then skips the following priority entirely. The fix detects when the current priority was removed (the pointer advanced past it) and calls `prev()` so that `next()` in the calling loop lands on the correct priority. Fixes #64653.
90f0d19 to
40ea968
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| * | ||
| * @ticket 64653 | ||
| */ | ||
| public function test_self_removing_callback_does_not_skip_next_priority() { |
There was a problem hiding this comment.
I can confirm this test fails without the fix applied:
1) Tests_Hooks_DoAction::test_self_removing_callback_does_not_skip_next_priority
Priority 100 should not be skipped when priority 50 removes itself during iteration.
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
Array &0 (
0 => 10
1 => 50
- 2 => 100
)
/var/www/tests/phpunit/tests/hooks/doAction.php:331
| * | ||
| * @ticket 64653 | ||
| */ | ||
| public function test_self_removing_callback_at_lowest_priority() { |
There was a problem hiding this comment.
This test does not fail without the fix applied.
Trac ticket: https://core.trac.wordpress.org/ticket/64653
When a callback removes itself during
do_action()/apply_filters()and is the sole callback at its priority,resort_active_iterations()positions the internal array pointer one step too far. The main loop'snext()call then skips the following priority entirely.Steps to reproduce
The bug requires: (1) a lower priority exists, (2) the removed callback is the only one at its priority.