diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 57cc8bd68e0..50b4b052e3b 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -1503,6 +1503,16 @@ public static function ensure_required_markup( Document $dom, $script_handles = array_keys( $amp_scripts ), array_merge( $script_handles, [ Amp::RUNTIME ] ) ); + + // Allow the amp-carousel script as a special case to be on the page when there is no since the + // amp-lightbox-gallery component will lazy-load the amp-carousel script when a lightbox is opened, and since + // amp-carousel v0.1 is still the 'latest' version, this can mean that fixes needed with the 0.2 version won't + // be present on the page. Adding the amp-carousel v0.2 script is a stated workaround suggested in an AMP core + // issue: . + if ( in_array( 'amp-lightbox-gallery', $script_handles, true ) ) { + $superfluous_script_handles = array_diff( $superfluous_script_handles, [ 'amp-carousel' ] ); + } + foreach ( $superfluous_script_handles as $superfluous_script_handle ) { if ( ! empty( $extension_specs[ $superfluous_script_handle ]['requires_usage'] ) ) { unset( $amp_scripts[ $superfluous_script_handle ] ); diff --git a/tests/php/test-class-amp-theme-support.php b/tests/php/test-class-amp-theme-support.php index 28f4222ec88..a041d319280 100644 --- a/tests/php/test-class-amp-theme-support.php +++ b/tests/php/test-class-amp-theme-support.php @@ -1354,7 +1354,7 @@ public function test_unneeded_scripts_get_removed() { AMP_Theme_Support::finish_init(); // These should all get removed, unless used. - $required_usage_grandfathered = [ + $required_usage_exempted = [ 'amp-anim', 'amp-ad', 'amp-mustache', @@ -1364,6 +1364,10 @@ public function test_unneeded_scripts_get_removed() { 'amp-live-list', ]; + $conditionally_allowed_usage = [ + 'amp-carousel', + ]; + // These also should get removed, unless used. $required_usage_error = [ 'amp-facebook-like', @@ -1384,7 +1388,11 @@ public function test_unneeded_scripts_get_removed() { - + + + + + @@ -1403,7 +1411,7 @@ public function test_unneeded_scripts_get_removed() { $expected_script_srcs = [ wp_scripts()->registered['amp-runtime']->src, ]; - foreach ( $required_usage_none as $handle ) { + foreach ( array_merge( $required_usage_none, $conditionally_allowed_usage ) as $handle ) { $expected_script_srcs[] = wp_scripts()->registered[ $handle ]->src; }