WordPress.org

Make WordPress Core

Ticket #35956: 35956_sort2.diff

File 35956_sort2.diff, 2.3 KB (added by gitlost, 6 years ago)

Update to save/restore $this->group.

  • src/wp-includes/class.wp-dependencies.php

     
    158158                        if ( $queued && !$moved ) // already queued and in the right group
    159159                                continue;
    160160
     161                        $this_group = $this->group; // Need to save group at this level...
     162
    161163                        $keep_going = true;
    162164                        if ( !isset($this->registered[$handle]) )
    163165                                $keep_going = false; // Item doesn't exist.
     
    166168                        elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $group ) )
    167169                                $keep_going = false; // Item requires dependencies that don't exist.
    168170
     171                        $this->group = $this_group; // ...and then restore it.
     172
    169173                        if ( ! $keep_going ) { // Either item or its dependencies don't exist.
    170174                                if ( $recursion )
    171175                                        return false; // Abort this branch.
  • src/wp-includes/class.wp-scripts.php

     
    356356         * @return bool True on success, false on failure.
    357357         */
    358358        public function all_deps( $handles, $recursion = false, $group = false ) {
     359
     360                if ( $recursion ) { // Need to go from highest group to lowest.
     361                        $this->usort_deps = $handles; // Used to make sort stable in usort_deps_cb() (optional but nice).
     362                        usort( $handles, array( $this, 'usort_deps_cb' ) );
     363                }
     364
    359365                $r = parent::all_deps( $handles, $recursion );
    360366                if ( ! $recursion ) {
    361367                        /**
     
    420426                $this->ext_version = '';
    421427                $this->ext_handles = '';
    422428        }
     429
     430        /**
     431         * Callback for usort to reverse sort dependency handles by group.
     432         */
     433        protected function usort_deps_cb( $a, $b ) {
     434                $a_grp = isset( $this->registered[$a]->args ) && $this->registered[$a]->args === 1 ? 1 : (int) $this->get_data( $a, 'group' );
     435                $b_grp = isset( $this->registered[$b]->args ) && $this->registered[$b]->args === 1 ? 1 : (int) $this->get_data( $b, 'group' );
     436                if ( $a_grp === $b_grp && isset( $this->usort_deps ) ) { // If available...
     437                        return array_search( $a, $this->usort_deps ) - array_search( $b, $this->usort_deps ); // ...make sort stable.
     438                }
     439                return $b_grp - $a_grp; // Reverse.
     440        }
    423441}