Skip to content

Commit 3fa890b

Browse files
committed
Hooks: Fix pointer over-advance in resort_active_iterations()
When a callback removes itself during execution and is the only entry at that priority, the internal array pointer is re-positioned by resort_active_iterations(). Before this fix, the pointer ended up at the next priority, but the subsequent next() call in the main apply_filters() loop would then advance it once more, skipping the next priority entirely. Calling prev() ensures the pointer is balanced so the next() call lands correctly on the intended priority. Fixes #64653.
1 parent 4d3b0b9 commit 3fa890b

File tree

3 files changed

+675
-0
lines changed

3 files changed

+675
-0
lines changed

src/wp-includes/class-wp-hook.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ private function resort_active_iterations( $new_priority = false, $priority_exis
150150
}
151151
}
152152

153+
//If the current priority was removed, step back so the next() call in the main loop lands correctly.
154+
if ( false !== current( $iteration ) && current( $iteration ) !== $current ) {
155+
prev( $iteration );
156+
}
157+
153158
// If we have a new priority that didn't exist, but ::apply_filters() or ::do_action() thinks it's the current priority...
154159
if ( $new_priority === $this->current_priority[ $index ] && ! $priority_existed ) {
155160
/*

0 commit comments

Comments
 (0)