Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#33144 closed defect (bug) (duplicate)

remove_filter's cleanup causes do_action to skip entire next priority block.

Reported by: dougwollison Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Plugins Keywords:
Focuses: Cc:


I have some plugins adding actions to save_post, one at priority 15, the other at priority 999.

The callback run at priority 15 starts off by removing itself before running since it ends up calling wp_update_post and of course needs to prevent an infinite loop.

However, when it's the only callback registered to that block, remove_filter will attempt to do some cleanup and unset that entry of the array since it's empty. This seems to cause the internal pointer within $wp_filter[save_post] to silently advance to the next block and then skip that via the next() call that controls the while loop.

Now, if the original callback adds itself back, everything's fine, but the code for said plugin has it call remove_action before proceeding with the checks for wether or not it should run at all, and so never adds itself back.

This is arguably the fault of the plugin and not the core, but I think that cleanup line should be removed to prevent bugs like this. Otherwise my only option without editing the plugin code is to add a throwaway hook at a priority between the first one and the second, so that it get's skipped and not the one that's needed.

Change History (1)

#1 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #9968 and #21169.

Note: See TracTickets for help on using tickets.