[wp-trac] [WordPress Trac] #41185: current_priority() in WP_Hook broken after adding callback inside same hook

WordPress Trac noreply at wordpress.org
Thu Jul 6 13:47:17 UTC 2017


#41185: current_priority() in WP_Hook broken after adding callback inside same hook
----------------------------------------+------------------------------
 Reporter:  kraftner                    |       Owner:
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  Plugins                     |     Version:  4.8
 Severity:  normal                      |  Resolution:
 Keywords:  has-unit-tests needs-patch  |     Focuses:
----------------------------------------+------------------------------

Comment (by kraftner):

 The more I look into it the more I come to the conclusion that the
 implementation of `current_priority()` as relying on the array pointer of
 `$this->iterations` as well as relying on `$wp_filter[ current_filter() ]`
 to get to that method at all is flawed. Let me explain:

 First problem is that relying on `$wp_filter[ current_filter() ]` as
 proposed in https://core.trac.wordpress.org/ticket/39007#comment:4 is
 fragile, e.g. when the underlying filter has had all hooks including the
 one currently running removed in the meantime which leads to the removal
 of the corresponding `WP_Hook` instance in `$wp_filter`. (See the newly
 added test. Also not sure if that might needs to be filed as a separate
 issue.)

 So even if you'd fix the array pointer (and work around the above
 mentioned issue with `$wp_filter[ current_filter() ]`) you still have the
 problem that at the point that you call `current_priority()`
 `$this->iterations` might not be available any more, e.g. when a hook
 removes itself as the last hook and is therefore cleared out at the
 beginning of `resort_active_iterations()`. This is because `current(
 $this->iterations ) === []` after the removal but we're still running a
 hook under a priority that we can't determine any more with the
 `current_priority()` method.

 I hope this is understandable as my head is already steaming right now...

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41185#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list