diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index 8f38a404933..a57829efd48 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -1462,7 +1462,7 @@ function amp_is_native_img_used() { * * @param bool $use_native Whether to use `img`. */ - return (bool) apply_filters( 'amp_native_img_used', false ); + return (bool) apply_filters( 'amp_native_img_used', true ); } /** diff --git a/includes/sanitizers/class-amp-img-sanitizer.php b/includes/sanitizers/class-amp-img-sanitizer.php index efd641b75a6..7d36819f4c0 100644 --- a/includes/sanitizers/class-amp-img-sanitizer.php +++ b/includes/sanitizers/class-amp-img-sanitizer.php @@ -54,7 +54,7 @@ class AMP_Img_Sanitizer extends AMP_Base_Sanitizer { */ protected $DEFAULT_ARGS = [ 'add_noscript_fallback' => true, - 'native_img_used' => false, + 'native_img_used' => true, ]; /** diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 4135cab6d0d..8cd819126ae 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -155,6 +155,7 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer { protected $DEFAULT_ARGS = [ 'disable_style_processing' => false, 'dynamic_element_selectors' => [ + 'amp-img', 'amp-list', 'amp-live-list', '[submit-error]', diff --git a/tests/php/test-amp-helper-functions.php b/tests/php/test-amp-helper-functions.php index b70d0881046..1709b07a6cf 100644 --- a/tests/php/test-amp-helper-functions.php +++ b/tests/php/test-amp-helper-functions.php @@ -1790,13 +1790,13 @@ public function test_amp_is_dev_mode() { * @covers ::amp_is_native_img_used() */ public function test_amp_is_native_img_used() { - $this->assertFalse( amp_is_native_img_used(), 'Expected to be disabled by default for now.' ); + $this->assertTrue( amp_is_native_img_used(), 'Expected to be disabled by default for now.' ); - add_filter( 'amp_native_img_used', '__return_true' ); - $this->assertTrue( amp_is_native_img_used() ); - - add_filter( 'amp_native_img_used', '__return_false', 20 ); + add_filter( 'amp_native_img_used', '__return_false' ); $this->assertFalse( amp_is_native_img_used() ); + + add_filter( 'amp_native_img_used', '__return_true', 20 ); + $this->assertTrue( amp_is_native_img_used() ); } /** diff --git a/tests/php/test-amp-img-sanitizer.php b/tests/php/test-amp-img-sanitizer.php index f77535ab80d..df5d652c1de 100644 --- a/tests/php/test-amp-img-sanitizer.php +++ b/tests/php/test-amp-img-sanitizer.php @@ -45,7 +45,7 @@ public function test_get_selector_conversion_mapping() { $with_defaults = new AMP_Img_Sanitizer( $dom ); $this->assertEquals( - [ 'img' => [ 'amp-img', 'amp-anim' ] ], + [], $with_defaults->get_selector_conversion_mapping() ); @@ -521,6 +521,11 @@ public function test_converter( $source, $expected = null, $args = [], $expected $error_codes = []; + $args = array_merge( + [ 'native_img_used' => false ], + $args + ); + $args = array_merge( [ 'use_document_element' => true, @@ -584,7 +589,7 @@ public function test_no_gif_image_scripts() { $expected = [ 'amp-anim' => true ]; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); - $sanitizer = new AMP_Img_Sanitizer( $dom ); + $sanitizer = new AMP_Img_Sanitizer( $dom, [ 'native_img_used' => false ] ); $sanitizer->sanitize(); $validating_sanitizer = new AMP_Tag_And_Attribute_Sanitizer( $dom ); @@ -609,7 +614,7 @@ public function test_image_block_link_to_media_file_with_lightbox() { $expected = ''; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); - $sanitizer = new AMP_Img_Sanitizer( $dom ); + $sanitizer = new AMP_Img_Sanitizer( $dom, [ 'native_img_used' => false ] ); $sanitizer->sanitize(); $sanitizer = new AMP_Tag_And_Attribute_Sanitizer( $dom ); @@ -630,7 +635,7 @@ public function test_image_block_link_to_media_file_and_alignment_with_lightbox( $expected = '
'; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); - $sanitizer = new AMP_Img_Sanitizer( $dom ); + $sanitizer = new AMP_Img_Sanitizer( $dom, [ 'native_img_used' => false ] ); $sanitizer->sanitize(); $sanitizer = new AMP_Tag_And_Attribute_Sanitizer( $dom ); diff --git a/tests/php/test-amp-style-sanitizer.php b/tests/php/test-amp-style-sanitizer.php index bed80db0232..da07c12ba1e 100644 --- a/tests/php/test-amp-style-sanitizer.php +++ b/tests/php/test-amp-style-sanitizer.php @@ -1298,6 +1298,9 @@ public function get_amp_selector_data() { sprintf( '', admin_url( 'images/wordpress-logo.png' ) ), 'div img.logo{border:solid 1px red}', 'div amp-img.logo{border:solid 1px red}', // Note amp-anim is still tree-shaken because it doesn't occur in the DOM. + [ + AMP_Img_Sanitizer::class => [ 'native_img_used' => false ], + ], ], 'img-missing-class' => [ sprintf( '', admin_url( 'images/wordpress-logo.png' ) ), @@ -1308,16 +1311,25 @@ public function get_amp_selector_data() { sprintf( '', admin_url( 'images/wordpress-logo.png' ), admin_url( 'images/spinner-2x.gif' ) ), 'div img{border:solid 1px red}', 'div amp-img,div amp-anim{border:solid 1px red}', + [ + AMP_Img_Sanitizer::class => [ 'native_img_used' => false ], + ], ], 'amp-img-and-amp-anim' => [ sprintf( '