Script Loader: Ignore deregistered dependencies in wp_dependencies_unique_hosts()
.
Prevents a PHP warning when a handle of a deregistered dependency is still in the queue. Fixes #37502. git-svn-id: https://develop.svn.wordpress.org/trunk@38174 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
11e4642c67
commit
48078058d7
@ -2874,6 +2874,10 @@ function wp_dependencies_unique_hosts() {
|
||||
foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) {
|
||||
if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) {
|
||||
foreach ( $dependencies->queue as $handle ) {
|
||||
if ( ! isset( $dependencies->registered[ $handle ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* @var _WP_Dependency $dependency */
|
||||
$dependency = $dependencies->registered[ $handle ];
|
||||
$parsed = wp_parse_url( $dependency->src );
|
||||
|
@ -163,4 +163,17 @@ class Tests_WP_Resource_Hints extends WP_UnitTestCase {
|
||||
$this->assertEquals( $expected, $actual );
|
||||
$this->assertNotContains( $unexpected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37502
|
||||
*/
|
||||
function test_deregistered_scripts_are_ignored() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org'>\n";
|
||||
|
||||
wp_enqueue_script( 'test-script', 'http://example.org/script.js' );
|
||||
wp_deregister_script( 'test-script' );
|
||||
|
||||
$actual = get_echo( 'wp_resource_hints' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user