[wp-trac] [WordPress Trac] #61263: Nested hook removal removes remaining hooks with higher priority
WordPress Trac
noreply at wordpress.org
Tue May 21 15:15:28 UTC 2024
#61263: Nested hook removal removes remaining hooks with higher priority
--------------------------+-----------------------------
Reporter: vendidero | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi there,
imagine the following nested hook code:
{{{#!php
<?php
add_action( 'wp_loaded', function() {
var_dump("loaded @ 1000");
exit();
}, 1000 );
add_action( 'wp_loaded', function() {
var_dump("loaded @ 999");
remove_all_actions( 'wp_loaded', 999 );
}, 999 );
}}}
What would the expected output be? I was expecting to see the "loaded @
999" and the "loaded @ 1000" output followed by a break/exit. What
actually happens is that there is only the "loaded @ 999" output print and
nothing else. This seems to be related with the
WP_Hook::resort_active_iterations() method which gets called right after
removing a nested filter. It seems to be resetting the array keys of the
priorities skips all the remaining, still registered filters when calling
remove_filter(s) from inside a filter with the same priority as the
current executed filter.
The example above doesn't make much sense as the wp_loaded hook is applied
once per request only. There do exist other hooks that may be applied more
than one time and therefor need to be cleared this way.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61263>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list