Make WordPress Core

Opened 11 years ago

Closed 7 years ago

Last modified 7 years ago

#27428 closed defect (bug) (worksforme)

Hook priority order not respected when callbacks added in-hook

Reported by: rarst's profile Rarst Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Plugins Keywords:
Focuses: Cc:

Description

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();

Change History (5)

#1 @SergeyBiryukov
11 years ago

  • Component changed from General to Plugins

#3 @DrewAPicture
9 years ago

Just tested, and can confirm that #17817 would fix this.

#4 @Rarst
7 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Confirm as fixed.

#5 @netweb
7 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.