diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php
index 48f66af6e25..d51b0a068d1 100644
--- a/includes/class-amp-theme-support.php
+++ b/includes/class-amp-theme-support.php
@@ -1530,7 +1530,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' )
) {
@@ -1550,7 +1550,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 b2cf202bcbd..11cd240410b 100644
--- a/tests/php/test-class-amp-theme-support.php
+++ b/tests/php/test-class-amp-theme-support.php
@@ -1416,6 +1416,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().
*
@@ -1484,6 +1496,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.
*