WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/06/2016 07:49:54 PM (4 years ago)
Author:
ocean90
Message:

Dependencies: Improve group processing of script dependencies.

This is a follow-up to [36604].

When processing dependencies $this->group will be the minimum of the script's registered group and all preceding siblings. This is wrong because only a scripts ancestors in the dependency chain should affect where it is loaded. Effectively $this->group introduced a form of global state which potentially corrupted the group of dependencies. Sorting covers up this problem.
The issue in #35873 was that script were not moving their dependencies to a lower group when necessary.

The fix:

  • In WP_Dependencies::all_deps() pass the new $group value to WP_Dependencies::all_deps(). Previously the wrong value was passed because the parent script could have moved with WP_Scripts::set_group().
  • In WP_Scripts::all_deps() pass the $group parameter to WP_Dependencies::all_deps() so it doesn't always use false for $group. Same for WP_Styles::all_deps().

Props stephenharris, gitlost.
Fixes #35956.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-dependencies.php

    r36744 r36871  
    7878     * @access public
    7979     * @since 2.8.0
     80     * @deprecated 4.5.0
    8081     * @var int
    8182     */
     
    162163                continue;
    163164
    164             $moved = $this->set_group( $handle, $recursion, $group );
     165            $moved     = $this->set_group( $handle, $recursion, $group );
     166            $new_group = $this->groups[ $handle ];
    165167
    166168            if ( $queued && !$moved ) // already queued and in the right group
     
    172174            elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) )
    173175                $keep_going = false; // Item requires dependencies that don't exist.
    174             elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $group ) )
     176            elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) )
    175177                $keep_going = false; // Item requires dependencies that don't exist.
    176178
     
    398400        $group = (int) $group;
    399401
    400         if ( $recursion ) {
    401             $group = min( $this->group, $group );
    402         }
    403 
    404         $this->group = $group;
    405 
    406         if ( isset($this->groups[$handle]) && $this->groups[$handle] <= $group )
    407             return false;
    408 
    409         $this->groups[$handle] = $group;
     402        if ( isset( $this->groups[ $handle ] ) && $this->groups[ $handle ] <= $group ) {
     403            return false;
     404        }
     405
     406        $this->groups[ $handle ] = $group;
     407
    410408        return true;
    411409    }
Note: See TracChangeset for help on using the changeset viewer.