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.
Built from https://develop.svn.wordpress.org/trunk@36871


git-svn-id: http://core.svn.wordpress.org/trunk@36838 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2016-03-06 19:50:27 +00:00
parent c73a812109
commit f4ef187c2c
4 changed files with 10 additions and 12 deletions

View File

@ -77,6 +77,7 @@ class WP_Dependencies {
*
* @access public
* @since 2.8.0
* @deprecated 4.5.0
* @var int
*/
public $group = 0;
@ -161,7 +162,8 @@ class WP_Dependencies {
if ( in_array($handle, $this->done, true) ) // Already done
continue;
$moved = $this->set_group( $handle, $recursion, $group );
$moved = $this->set_group( $handle, $recursion, $group );
$new_group = $this->groups[ $handle ];
if ( $queued && !$moved ) // already queued and in the right group
continue;
@ -171,7 +173,7 @@ class WP_Dependencies {
$keep_going = false; // Item doesn't exist.
elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) )
$keep_going = false; // Item requires dependencies that don't exist.
elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $group ) )
elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) )
$keep_going = false; // Item requires dependencies that don't exist.
if ( ! $keep_going ) { // Either item or its dependencies don't exist.
@ -397,16 +399,12 @@ class WP_Dependencies {
public function set_group( $handle, $recursion, $group ) {
$group = (int) $group;
if ( $recursion ) {
$group = min( $this->group, $group );
if ( isset( $this->groups[ $handle ] ) && $this->groups[ $handle ] <= $group ) {
return false;
}
$this->group = $group;
$this->groups[ $handle ] = $group;
if ( isset($this->groups[$handle]) && $this->groups[$handle] <= $group )
return false;
$this->groups[$handle] = $group;
return true;
}

View File

@ -509,7 +509,7 @@ class WP_Scripts extends WP_Dependencies {
* @return bool True on success, false on failure.
*/
public function all_deps( $handles, $recursion = false, $group = false ) {
$r = parent::all_deps( $handles, $recursion );
$r = parent::all_deps( $handles, $recursion, $group );
if ( ! $recursion ) {
/**
* Filter the list of script dependencies left to print.

View File

@ -310,7 +310,7 @@ class WP_Styles extends WP_Dependencies {
* @return bool True on success, false on failure.
*/
public function all_deps( $handles, $recursion = false, $group = false ) {
$r = parent::all_deps( $handles, $recursion );
$r = parent::all_deps( $handles, $recursion, $group );
if ( ! $recursion ) {
/**
* Filter the array of enqueued styles before processing for output.

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-beta2-36870';
$wp_version = '4.5-beta2-36871';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.