[wp-trac] [WordPress Trac] #9968: dynamically adding/removing filters breaks plugins
WordPress Trac
noreply at wordpress.org
Fri Feb 13 13:37:18 UTC 2015
#9968: dynamically adding/removing filters breaks plugins
-------------------------------------+-----------------------------
Reporter: Denis-de-Bernardy | Owner:
Type: defect (bug) | Status: reopened
Priority: low | Milestone: Future Release
Component: Plugins | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-testing | Focuses:
-------------------------------------+-----------------------------
Comment (by nikolov.tmw):
Might be a silly question, but why not just remove
{{{
if ( empty( $GLOBALS['wp_filter'][ $tag ][ $priority ] ) ) {
unset( $GLOBALS['wp_filter'][ $tag ][ $priority ] );
}
}}}
From `remove_filter()`? Because I believe the problem occurs when you
remove a priority key(once there are more callbacks for that priority for
the given action/filter) from the array.
In my testing commenting-out `unset(...` fixed the issue altogether.
However I'm not familiar enough with the inner-workings of the filter API
to foresee whether doing so will create any side effects.
I believe that having an empty priority key should not be too much of an
issue, since we're using `foreach( (array) current( $wp_filter[$tag[ )...
)` in order to go through the different priorities, which means that if a
key is empty, then simply nothing will happen(you'll move to the next
priority in the stack).
I was just debugging a conflict between plugins and calling
`remove_action()` was the culprit. To be honest, having a buggy
implementation of `remove_filter()` and `remove_action()` is not really
good(because sometimes you do need to have filters/actions that only run
once).
Feedback from someone with more insight would be appreciated :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/9968#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list