Make WordPress Core

Ticket #58458: 58458.patch

File 58458.patch, 2.6 KB (added by bor0, 22 months ago)
  • src/wp-includes/class-wp-hook.php

     
    2727        public $callbacks = array();
    2828
    2929        /**
     30         * Hook callbacks keys.
     31         *
     32         * @since 6.x
     33         * @var array
     34         */
     35        protected $callbacks_keys = array();
     36
     37        /**
    3038         * The priority keys of actively running iterations of a hook.
    3139         *
    3240         * @since 4.7.0
     
    8694                        ksort( $this->callbacks, SORT_NUMERIC );
    8795                }
    8896
     97
     98                $this->callbacks_keys = array_keys( $this->callbacks );
     99
    89100                if ( $this->nesting_level > 0 ) {
    90101                        $this->resort_active_iterations( $priority, $priority_existed );
    91102                }
     
    102113         *                                    filter was added. Default false.
    103114         */
    104115        private function resort_active_iterations( $new_priority = false, $priority_existed = false ) {
    105                 $new_priorities = array_keys( $this->callbacks );
     116                $new_priorities = $this->callbacks_keys;
    106117
    107118                // If there are no remaining hooks, clear out all running iterations.
    108119                if ( ! $new_priorities ) {
     
    187198                        if ( ! $this->callbacks[ $priority ] ) {
    188199                                unset( $this->callbacks[ $priority ] );
    189200
     201                                $this->callbacks_keys = array_keys( $this->callbacks );
     202
    190203                                if ( $this->nesting_level > 0 ) {
    191204                                        $this->resort_active_iterations();
    192205                                }
     
    263276
    264277                if ( false === $priority ) {
    265278                        $this->callbacks = array();
     279                        $this->callbacks_keys = array();
    266280                } elseif ( isset( $this->callbacks[ $priority ] ) ) {
    267281                        unset( $this->callbacks[ $priority ] );
     282                        $this->callbacks_keys = array_keys( $this->callbacks );
    268283                }
    269284
     285
    270286                if ( $this->nesting_level > 0 ) {
    271287                        $this->resort_active_iterations();
    272288                }
     
    289305
    290306                $nesting_level = $this->nesting_level++;
    291307
    292                 $this->iterations[ $nesting_level ] = array_keys( $this->callbacks );
     308                $this->iterations[ $nesting_level ] = $this->callbacks_keys;
    293309
    294310                $num_args = count( $args );
    295311
     
    348364         */
    349365        public function do_all_hook( &$args ) {
    350366                $nesting_level                      = $this->nesting_level++;
    351                 $this->iterations[ $nesting_level ] = array_keys( $this->callbacks );
     367                $this->iterations[ $nesting_level ] = $this->callbacks_keys;
    352368
    353369                do {
    354370                        $priority = current( $this->iterations[ $nesting_level ] );
     
    481497                } else {
    482498                        $this->callbacks[ $offset ] = $value;
    483499                }
     500
     501                $this->callbacks_keys = array_keys( $this->callbacks );
    484502        }
    485503
    486504        /**
     
    495513        #[ReturnTypeWillChange]
    496514        public function offsetUnset( $offset ) {
    497515                unset( $this->callbacks[ $offset ] );
     516                $this->callbacks_keys = array_keys( $this->callbacks );
    498517        }
    499518
    500519        /**