[wp-trac] [WordPress Trac] #28142: removing all callbacks from an action results in NULL callback

WordPress Trac noreply at wordpress.org
Mon May 5 22:02:12 UTC 2014


#28142: removing all callbacks from an action results in NULL callback
--------------------------+-----------------------------
 Reporter:  sphoid        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Plugins       |    Version:  3.8.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 If you remove all callbacks for an action and the action is triggered
 afterwards you will receive a php warning (Warning: call_user_func_array()
 expects parameter 1 to be a valid callback, no array or string given)

 The following code will demonstrate this:
 {{{
 function do_something(){

         echo 'do_something called<br/>';

         do_action( 'test_action_1234', 'test' );

 }

 function test_action_callback( $param ){

         echo 'test_action happened<br/>';

 }
 add_action( 'test_action_1234', 'test_action_callback', 10 );

 do_something();

 remove_action( 'test_action_1234', 'test_action_callback', 10 );

 do_something();
 }}}

 This happens on line 427 in wp-includes/plugin.php:
 {{{
 foreach ( (array) current($wp_filter[$tag]) as $the_ )
 }}}

 when {{{$wp_filter['test_action_1234']}}} is empty it is converted to a
 single element array that contains a null value which php then complains
 about not being a valid callback, which makes sense.

 Expected behavior is that no warning should occur when all callbacks are
 removed from an action.

 When all tags are removed for an action then the tag should be removed
 from $wp_filter to prevent this. I am attaching a patch for wp-
 includes/plugin.php remove_filter function that does this.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28142>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list