diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 83eabe8937..4e049d5714 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -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 ); diff --git a/tests/phpunit/tests/general/resourceHints.php b/tests/phpunit/tests/general/resourceHints.php index 75468758ec..f6da5574cc 100644 --- a/tests/phpunit/tests/general/resourceHints.php +++ b/tests/phpunit/tests/general/resourceHints.php @@ -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 = "\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 ); + } }