diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 158a635eb73..c67be4cccf8 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -1566,7 +1566,7 @@ protected static function is_exclusively_dependent( WP_Dependencies $dependencie */ public static function filter_admin_bar_style_loader_tag( $tag, $handle ) { if ( - in_array( $handle, wp_styles()->registered['admin-bar']->deps, true ) ? + is_array( wp_styles()->registered['admin-bar']->deps ) && in_array( $handle, wp_styles()->registered['admin-bar']->deps, true ) ? self::is_exclusively_dependent( wp_styles(), $handle, 'admin-bar' ) : self::has_dependency( wp_styles(), $handle, 'admin-bar' ) ) { @@ -1586,7 +1586,7 @@ public static function filter_admin_bar_style_loader_tag( $tag, $handle ) { */ public static function filter_admin_bar_script_loader_tag( $tag, $handle ) { if ( - in_array( $handle, wp_scripts()->registered['admin-bar']->deps, true ) ? + is_array( wp_scripts()->registered['admin-bar']->deps ) && in_array( $handle, wp_scripts()->registered['admin-bar']->deps, true ) ? self::is_exclusively_dependent( wp_scripts(), $handle, 'admin-bar' ) : self::has_dependency( wp_scripts(), $handle, 'admin-bar' ) ) { diff --git a/tests/php/test-class-amp-theme-support.php b/tests/php/test-class-amp-theme-support.php index 1d836a180df..f2e5eb2ee58 100644 --- a/tests/php/test-class-amp-theme-support.php +++ b/tests/php/test-class-amp-theme-support.php @@ -1445,6 +1445,18 @@ public function test_filter_admin_bar_style_loader_tag( $setup_callback, $assert $assert_callback( new DOMXPath( $dom ) ); } + /** + * Test filter_admin_bar_style_loader_tag when ->deps is not an array. + * + * @covers \AMP_Theme_Support::filter_admin_bar_style_loader_tag() + */ + public function test_filter_admin_bar_style_loader_tag_non_array() { + wp_enqueue_style( 'admin-bar' ); + $GLOBALS['wp_styles']->registered['admin-bar']->deps = null; + $tag = ''; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet + $this->assertEquals( $tag, AMP_Theme_Support::filter_admin_bar_style_loader_tag( $tag, 'baz' ) ); + } + /** * Get data to test AMP_Theme_Support::filter_admin_bar_script_loader_tag(). * @@ -1547,6 +1559,18 @@ public function test_filter_admin_bar_script_loader_tag( $setup_callback, $asser $assert_callback( new DOMXPath( $dom ) ); } + /** + * Test filter_admin_bar_script_loader_tag when ->deps is not an array. + * + * @covers \AMP_Theme_Support::filter_admin_bar_script_loader_tag() + */ + public function test_filter_admin_bar_script_loader_tag_non_array() { + wp_enqueue_script( 'admin-bar' ); + $GLOBALS['wp_scripts']->registered['admin-bar']->deps = null; + $tag = ''; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript + $this->assertEquals( $tag, AMP_Theme_Support::filter_admin_bar_script_loader_tag( $tag, 'example' ) ); + } + /** * Test init_admin_bar to ensure dashicons are not added to dev mode when directly enqueued. *