#27428 closed defect (bug) (worksforme)
Hook priority order not respected when callbacks added in-hook
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 3.8.1 |
| Component: | Plugins | Keywords: | |
| Focuses: | Cc: |
Description
Sequence of actions producing unexpected result:
- Some callbacks are added to hook
- One of callbacks runs at priority 0 and adds more callbacks to same hook
- 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();
Change History (5)
Note: See
TracTickets for help on using
tickets.
Related: #9968, #17817, #19015, #20998, #21169, #23035, #26239.