Changeset 58974
- Timestamp:
- 09/03/2024 05:05:33 PM (5 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r58942 r58974 1974 1974 */ 1975 1975 function wp_img_tag_add_loading_optimization_attrs( $image, $context ) { 1976 $src = preg_match( '/ src=["\']?([^"\']*)/i', $image, $matche_src ) ? $matche_src[1] : null; 1976 1977 $width = preg_match( '/ width=["\']([0-9]+)["\']/', $image, $match_width ) ? (int) $match_width[1] : null; 1977 1978 $height = preg_match( '/ height=["\']([0-9]+)["\']/', $image, $match_height ) ? (int) $match_height[1] : null; … … 1988 1989 'img', 1989 1990 array( 1991 'src' => $src, 1990 1992 'width' => $width, 1991 1993 'height' => $height, -
trunk/tests/phpunit/tests/media.php
r58773 r58974 5580 5580 5581 5581 /** 5582 * Tests that wp_img_tag_add_loading_optimization_attrs() passes the 'src' attribute to wp_get_loading_optimization_attributes(). 5583 * 5584 * @ticket 61436 5585 * 5586 * @covers ::wp_img_tag_add_loading_optimization_attrs 5587 */ 5588 public function test_wp_img_tag_add_loading_optimization_attrs_passes_src() { 5589 add_filter( 5590 'wp_get_loading_optimization_attributes', 5591 static function ( $loading_attrs, $tag_name, $attr ) { 5592 if ( 5593 'img' === $tag_name && 5594 isset( $attr['src'] ) && 5595 'https://example.org/a-specific-image.jpg' === $attr['src'] 5596 ) { 5597 $loading_attrs['fetchpriority'] = 'low'; 5598 $loading_attrs['loading'] = 'eager'; 5599 } 5600 return $loading_attrs; 5601 }, 5602 10, 5603 3 5604 ); 5605 5606 $image = '<img src="https://example.org/a-specific-image.jpg" width="1280" height="720">'; 5607 $expected = '<img fetchpriority="low" loading="eager" decoding="async" src="https://example.org/a-specific-image.jpg" width="1280" height="720">'; 5608 5609 // Ensure attributes are modified because image src was matched. 5610 $this->assertSame( 5611 $expected, 5612 wp_img_tag_add_loading_optimization_attrs( $image, 'the_content' ), 5613 'fetchpriority should be low when src is matched.' 5614 ); 5615 } 5616 5617 /** 5582 5618 * @ticket 58235 5583 5619 *
Note: See TracChangeset
for help on using the changeset viewer.