[wp-trac] [WordPress Trac] #39225: Callbacks with a higher priority within the same hook no longer get triggred since 4.7
WordPress Trac
noreply at wordpress.org
Fri Mar 15 02:18:13 UTC 2019
#39225: Callbacks with a higher priority within the same hook no longer get
triggred since 4.7
--------------------------+------------------------
Reporter: miunosoft | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Plugins | Version: 4.7
Severity: normal | Resolution: duplicate
Keywords: | Focuses:
--------------------------+------------------------
Changes (by desrosj):
* status: new => closed
* resolution: => duplicate
* milestone: Awaiting Review =>
Old description:
> 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
> <?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.
New description:
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
<?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.
--
Comment:
Duplicate of #38011.
Going to close this out since there has been no further feedback on this.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39225#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list