[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
Sat Dec 10 14:07:48 UTC 2016


#39225: Callbacks with a higher priority within the same hook no longer get
triggred since 4.7
--------------------------+-----------------------------
 Reporter:  miunosoft     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Plugins       |    Version:  4.7
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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.

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


More information about the wp-trac mailing list