`wp_script_is( ..., 'enqueued' )` needs to check dependencies recursively - a single item's dependencies may only be a subset of the full dependency tree. Adds a new method on `WP_Dependencies` called `->recurse_deps()`.
Adds unit test. Props wonderboymusic, SergeyBiryukov, mikejolley. Fixes #28404. Built from https://develop.svn.wordpress.org/trunk@29252 git-svn-id: http://core.svn.wordpress.org/trunk@29035 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
baf7f5604d
commit
f93abf2bea
|
@ -324,6 +324,31 @@ class WP_Dependencies {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively search the passed dependency tree for $handle
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $queue An array of queued _WP_Dependency handle objects.
|
||||
* @param string $handle Name of the item. Should be unique.
|
||||
* @return boolean Whether the handle is found after recursively searching the dependency tree.
|
||||
*/
|
||||
protected function recurse_deps( $queue, $handle ) {
|
||||
foreach ( $queue as $queued ) {
|
||||
if ( ! isset( $this->registered[ $queued ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( in_array( $handle, $this->registered[ $queued ]->deps ) ) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->recurse_deps( $this->registered[ $queued ]->deps, $handle );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query list for an item.
|
||||
*
|
||||
|
@ -344,7 +369,10 @@ class WP_Dependencies {
|
|||
|
||||
case 'enqueued' :
|
||||
case 'queue' :
|
||||
return in_array( $handle, $this->queue );
|
||||
if ( in_array( $handle, $this->queue ) ) {
|
||||
return true;
|
||||
}
|
||||
return $this->recurse_deps( $this->queue, $handle );
|
||||
|
||||
case 'to_do' :
|
||||
case 'to_print': // back compat
|
||||
|
|
Loading…
Reference in New Issue