Changeset 56164
- Timestamp:
- 07/07/2023 06:06:49 PM (17 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r56154 r56164 5667 5667 * Skip programmatically created images within post content as they need to be handled together with the other 5668 5668 * images within the post content. 5669 * Without this clause, they would already be counted below which skews the number and can result in the first 5670 * post content image being lazy-loaded only because there are images elsewhere in the post content. 5669 * Without this clause, they would already be considered below which skews the image count and can result in 5670 * the first post content image being lazy-loaded or an image further down the page being marked as a high 5671 * priority. 5671 5672 */ 5672 5673 if ( doing_filter( 'the_content' ) ) { 5673 return $ postprocess( $loading_attrs, true );5674 return $loading_attrs; 5674 5675 } 5675 5676 -
trunk/tests/phpunit/tests/media.php
r56154 r56164 4135 4135 * @covers ::wp_get_loading_optimization_attributes 4136 4136 */ 4137 public function test_wp_filter_content_tags_does_not_ lazy_load_special_images_within_the_content() {4137 public function test_wp_filter_content_tags_does_not_apply_loading_optimization_to_special_images_within_the_content() { 4138 4138 global $wp_query, $wp_the_query; 4139 4139 4140 // Force no lazy-loading on the image tag expected in the content. 4141 $expected_content = wpautop( 4142 wp_get_attachment_image( 4143 self::$large_id, 4144 'large', 4145 false, 4146 array( 4147 'loading' => false, 4148 'fetchpriority' => 'high', 4149 ) 4140 // Force no lazy-loading or fetchpriority on the image tag expected in the content. 4141 $expected_image = wp_get_attachment_image( 4142 self::$large_id, 4143 'large', 4144 false, 4145 array( 4146 'loading' => false, 4147 'fetchpriority' => false, 4150 4148 ) 4151 4149 ); … … 4153 4151 // Reset high priority flag as the forced `fetchpriority="high"` above already modified it. 4154 4152 $this->reset_high_priority_element_flag(); 4153 4154 $image_within_content = ''; 4155 4155 4156 4156 // Overwrite post content with an image. 4157 4157 add_filter( 4158 4158 'the_content', 4159 static function() {4159 static function() use ( &$image_within_content ) { 4160 4160 // Replace content with an image tag, i.e. the 'wp_get_attachment_image' context is used while running 'the_content' filter. 4161 return wp_get_attachment_image( self::$large_id, 'large', false ); 4161 $image_within_content = wp_get_attachment_image( self::$large_id, 'large', false ); 4162 return $image_within_content; 4162 4163 }, 4163 4164 9 // Run before wp_filter_content_tags(). … … 4179 4180 } 4180 4181 4181 // Ensure that parsed content has the image without lazy-loading. 4182 $this->assertSame( $expected_content, $content ); 4182 // Ensure that parsed image within content does not receive any loading optimization attributes. 4183 $this->assertSame( $expected_image, $image_within_content, 'Image with wp_get_attachment_image context within post content should not receive loading optimization attributes' ); 4184 4185 // Ensure that parsed content has the image with fetchpriority as it is the first large image. 4186 $expected_content = wpautop( str_replace( '<img ', '<img fetchpriority="high" ', $expected_image ) ); 4187 $this->assertSame( $expected_content, $content, 'Post content with programmatically injected image is missing loading optimization attributes' ); 4183 4188 } 4184 4189 … … 4504 4509 4505 4510 /** 4506 * Tests that wp_get_loading_optimization_attributes() returns falsefor special contexts when they're used within 'the_content' filter.4511 * Tests that wp_get_loading_optimization_attributes() does not modify any attributes for special contexts when they're used within 'the_content' filter. 4507 4512 * 4508 4513 * @ticket 58089 … … 4515 4520 * @param string $context Context for the element for which the `loading` attribute value is requested. 4516 4521 */ 4517 public function test_wp_get_loading_optimization_attributes_should_ return_false_for_special_contexts_within_the_content( $context ) {4522 public function test_wp_get_loading_optimization_attributes_should_not_modify_images_for_special_contexts_within_the_content( $context ) { 4518 4523 remove_all_filters( 'the_content' ); 4519 4524 … … 4529 4534 apply_filters( 'the_content', '' ); 4530 4535 4531 $this->assertSame( 4532 array( 'fetchpriority' => 'high' ), 4533 $result, 4534 'First large image is loaded with high fetchpriority.' 4535 ); 4536 $this->assertSame( array(), $result ); 4536 4537 } 4537 4538
Note: See TracChangeset
for help on using the changeset viewer.