[wp-trac] [WordPress Trac] #19306: remove_all_filters() should set to array(), not unset

WordPress Trac wp-trac at lists.automattic.com
Sun Nov 20 19:11:49 UTC 2011


#19306: remove_all_filters() should set to array(), not unset
-------------------------+-----------------------------
 Reporter:  nacin        |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Plugins      |    Version:
 Severity:  normal       |   Keywords:  has-patch
-------------------------+-----------------------------
 Consider this use case: You want to hook into priority 0 of an action and
 run remove_all_actions() for all other callbacks.

 Since we use current() and next() to iterate, rather than making a copy of
 $wp_filter to loop through it, this should work.

 Unfortunately, current() and next() expect an array, and only stop when
 next() returns === false. remove_all_filters() does an unset() on
 $wp_filter[$tag], which means next() returns A) a warning, and B) null.
 The null causes an indefinite loop.

 Test code:
 {{{
 add_filter( 'test_filter', function() { remove_all_filters( 'test_filter'
 ); return 0; }, 0 );
 add_filter( 'test_filter', function() { return 1; }, 1 );
 add_filter( 'test_filter', function() { return 2; }, 2 );
 var_dump( apply_filters( 'test_filter', -1 ) );
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19306>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list