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. git-svn-id: https://develop.svn.wordpress.org/trunk@29252 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
36e455d018
commit
77ee35c4eb
@ -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.
|
* Query list for an item.
|
||||||
*
|
*
|
||||||
@ -344,7 +369,10 @@ class WP_Dependencies {
|
|||||||
|
|
||||||
case 'enqueued' :
|
case 'enqueued' :
|
||||||
case 'queue' :
|
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_do' :
|
||||||
case 'to_print': // back compat
|
case 'to_print': // back compat
|
||||||
|
@ -69,4 +69,16 @@ class Tests_Dependencies_jQuery extends WP_UnitTestCase {
|
|||||||
$contents = trim( file_get_contents( ABSPATH . WPINC . '/js/jquery/jquery.js' ) );
|
$contents = trim( file_get_contents( ABSPATH . WPINC . '/js/jquery/jquery.js' ) );
|
||||||
$this->assertFalse( strpos( $contents, 'sourceMappingURL' ), 'Presence of sourceMappingURL' );
|
$this->assertFalse( strpos( $contents, 'sourceMappingURL' ), 'Presence of sourceMappingURL' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 28404
|
||||||
|
*/
|
||||||
|
function test_wp_script_is_dep_enqueued() {
|
||||||
|
wp_enqueue_script( 'jquery-ui-accordion' );
|
||||||
|
|
||||||
|
$this->assertTrue( wp_script_is( 'jquery', 'enqueued' ) );
|
||||||
|
$this->assertFalse( wp_script_is( 'underscore', 'enqueued' ) );
|
||||||
|
|
||||||
|
unset( $GLOBALS['wp_scripts'] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user