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:
Dominik Schilling 2016-07-31 18:24:21 +00:00
parent 11e4642c67
commit 48078058d7
2 changed files with 17 additions and 0 deletions

View File

@ -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 );

View File

@ -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 );
}
}