[wp-trac] [WordPress Trac] #65167: WP_Hook: Self-removing callback causes the next priority to be skipped
WordPress Trac
noreply at wordpress.org
Tue May 5 16:18:26 UTC 2026
#65167: WP_Hook: Self-removing callback causes the next priority to be skipped
--------------------------+-----------------------------
Reporter: obenland | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: 4.7
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
When a callback running inside `apply_filters()` is the only one at its
priority and it removes itself (or another callback empties that bucket),
`WP_Hook` silently skips the callbacks at the next remaining priority, but
only when at least one earlier-priority callback has already run.
==== Conditions to reproduce
- A filter has callbacks at three priorities, e.g. 5, 10, 20.
- The callback at priority 10 is the only one at that priority and calls
`remove_filter()` on itself.
- During `apply_filters()`, the callback at priority 20 is silently
skipped.
If priority 5 is removed from the example, all callbacks fire correctly.
The bug only manifests when at least one earlier-priority callback has
already run.
==== Root cause
The bug predates `WP_Hook`. The pre-WP_Hook array-based `apply_filters()`
had the same misbehavior: when a callback unset the priority bucket the
internal array pointer was on, PHP silently auto-advanced the pointer to
the next valid key, and the trailing `next()` then overshot it. `WP_Hook`
(introduced in [38571] / 4.7.0) replaced PHP's implicit auto-advance with
an explicit forward-walk in `resort_active_iterations()`, but preserved
the same overshoot. The add-side of `resort_active_iterations()` already
has symmetric handling for callbacks added at the current priority during
iteration; the remove side is missing the equivalent fix.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65167>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list