Make WordPress Core

Opened 5 weeks ago

#61263 new defect (bug)

Nested hook removal removes remaining hooks with higher priority

Reported by: vendidero's profile vendidero Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

Hi there,

imagine the following nested hook code:

<?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.

Change History (0)

Note: See TracTickets for help on using tickets.