[wp-trac] [WordPress Trac] #40393: Using remove_action within an action callback skips over execution of other callbacks with lower priority

WordPress Trac noreply at wordpress.org
Fri Jul 21 20:26:19 UTC 2017


#40393: Using remove_action within an action callback skips over execution of other
callbacks with lower priority
--------------------------+------------------------------
 Reporter:  weeblrpress   |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Plugins       |     Version:
 Severity:  major         |  Resolution:
 Keywords:  dev-feedback  |     Focuses:
--------------------------+------------------------------

Comment (by weeblrpress):

 @mgibbs189 @boonebgorges

 From recollection, it was coming from the main loop in
 WP_Hook::apply_filters():
 {{{#!php
 <?php

 this->iterations[ $nesting_level ] = array_keys( $this->callbacks );

 do {
   /* iterate over current priority level */
   foreach ( $this->callbacks[ $priority ] as $the_ ) {

   $value = call_user_func_array( $the_['function'], $args );

   /* end iterate over current priority level */
   }

 } while ( false !== next( $this->iterations[ $nesting_level ] ) );
 }}}

 The while statement execute a next on the array to get callbacks for next
 priority level. But if remove_action is called upon the currently being
 executed action during all_user_func_array(), and current action is the
 only one in this prio level, then the callback set is removed:

 from WP_Hook::remove_filter():

 {{{#!php
 <?php

 if ( $exists ) {
         unset( $this->callbacks[ $priority ][ $function_key ] );
         if ( ! $this->callbacks[ $priority ] ) {
                 unset( $this->callbacks[ $priority ] );
                 if ( $this->nesting_level > 0 ) {
                         $this->resort_active_iterations();
                 }
         }
 }
 }}}

 So when next() is executed, one priority level is skipped.

 Hope this helps, maybe the fix is that remove_filter should not remove the
 callback priority level?

 Rgds

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


More information about the wp-trac mailing list