Opened 8 years ago
Closed 6 years ago
#39225 closed defect (bug) (duplicate)
Callbacks with a higher priority within the same hook no longer get triggred since 4.7
Reported by: | miunosoft | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7 |
Component: | Plugins | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
Hi,
It seems callback functions registered with a higher priority than a currently executed callback with the same hook do not get called.
The below is a demonstration plugin that illustrates the problem.
<?php /** * Plugin Name: Test - Hooks Behaviour 47 vs 4.6.x or below * Description: Tests the hooks behaviour to make comparision between WordPress 4.7 and 4.6.x or below. * Version: 1.0 */ class TestActionHookBehaviour { private $_sHookName = ''; private $_sLogFileName = ''; private $_sCallID = ''; public function __construct( $sHookName ) { $this->_sHookName = $sHookName; $this->_sLogFileName = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . basename( get_class() ) . '_' . date( "Ymd" ) . '.log'; $this->_sCallID = uniqid(); add_action( $this->_sHookName, array( $this, 'doAction' ), 10 ); do_action( $this->_sHookName ); } public function doAction() { $this->_log( __METHOD__ . ' ' . current_filter() ); // Register a callback with the same action while in the action with a higher priority. add_action( $this->_sHookName, array( $this, 'doWithinSameAction' ), 1 ); } /** * This method is called in v4.6.x or below but not in v4.7. */ public function doWithinSameAction() { $this->_log( __METHOD__ . ' called.' ); } private function _log( $sMessage ) { file_put_contents( $this->_sLogFileName, // file name $this->_sCallID . ' ' . $sMessage . PHP_EOL, FILE_APPEND ); } } new TestActionHookBehaviour( 'my_custom_action' );
If you run this in WordPress 4.7, the doWithinSameAction()
method never gets called while it does in WordPress 4.6 or below.
Change History (2)
Note: See
TracTickets for help on using
tickets.
Sounds like a duplicate of #38011, assuming that higher means earlier, which I think is true here.