[wp-trac] [WordPress Trac] #27428: Hook priority order not respected when callbacks added in-hook

WordPress Trac noreply at wordpress.org
Sat Mar 15 22:18:08 UTC 2014


#27428: Hook priority order not respected when callbacks added in-hook
--------------------------+-----------------------------
 Reporter:  Rarst         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.8.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Sequence of actions producing unexpected result:

 1. Some callbacks are added to hook
 2. One of callbacks runs at priority 0 and adds more callbacks to same
 hook
 3. Remaining callbacks do not fire in expected (priority ascending) order

 Code demonstrating the issue:

 {{{
 class Nervous_Breakdown {

         public $priorities = array();

         public function __construct() {

                 add_action( __CLASS__, array( $this, 'add' ), 0 );
                 add_action( __CLASS__, array( $this, 'log' ), 0 );
                 add_action( __CLASS__, array( $this, 'log' ), 10 );

                 do_action( __CLASS__ );
                 var_dump( 'Priorities fired in order: ' . implode( ' >> ',
 $this->priorities ) );
                 // Result is 'Priorities fired in order: 0 >> 10 >> 2'
         }

         public function add(  ) {

                 add_action( __CLASS__, array( $this, 'log' ), 2 );
         }

         public function log() {

                 global $wp_filter;
                 $this->priorities[] = key( $wp_filter[current_filter()] );
         }
 }

 new Nervous_Breakdown();
 }}}

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


More information about the wp-trac mailing list