diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index ce05298b50..c380505762 100644
a
|
b
|
function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f |
1076 | 1076 | } |
1077 | 1077 | } |
1078 | 1078 | |
| 1079 | $attr['decoding'] = 'async'; |
| 1080 | |
1079 | 1081 | /** |
1080 | 1082 | * Filters the list of attachment image attributes. |
1081 | 1083 | * |
… |
… |
function wp_filter_content_tags( $content, $context = null ) { |
1842 | 1844 | $filtered_image = wp_img_tag_add_loading_attr( $filtered_image, $context ); |
1843 | 1845 | } |
1844 | 1846 | |
| 1847 | // Add 'decoding=async' attribute unless a 'decoding' attribute is already present. |
| 1848 | if ( false === strpos( $filtered_image, ' decoding=' ) ) { |
| 1849 | $filtered_image = wp_img_tag_add_decoding_async_attr( $filtered_image ); |
| 1850 | } |
| 1851 | |
1845 | 1852 | if ( $filtered_image !== $match[0] ) { |
1846 | 1853 | $content = str_replace( $match[0], $filtered_image, $content ); |
1847 | 1854 | } |
… |
… |
function wp_img_tag_add_loading_attr( $image, $context ) { |
1910 | 1917 | return $image; |
1911 | 1918 | } |
1912 | 1919 | |
| 1920 | /** |
| 1921 | * Adds `decoding=async` attribute to an `img` HTML tag. |
| 1922 | * |
| 1923 | * @since 5.9.0 |
| 1924 | * |
| 1925 | * @param string $image The HTML `img` tag where the attribute should be added. |
| 1926 | * @return string Converted `img` tag with `decoding=async` attribute added. |
| 1927 | */ |
| 1928 | function wp_img_tag_add_decoding_async_attr( $image ) { |
| 1929 | return str_replace( '<img ', '<img decoding="async" ', $image ); |
| 1930 | } |
| 1931 | |
1913 | 1932 | /** |
1914 | 1933 | * Adds `width` and `height` attributes to an `img` HTML tag. |
1915 | 1934 | * |
diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php
index e30fad1808..7206230aee 100644
a
|
b
|
if ( ! function_exists( 'get_avatar' ) ) : |
2675 | 2675 | 'force_display' => false, |
2676 | 2676 | 'loading' => null, |
2677 | 2677 | 'extra_attr' => '', |
| 2678 | 'decoding' => 'async', |
2678 | 2679 | ); |
2679 | 2680 | |
2680 | 2681 | if ( wp_lazy_loading_enabled( 'img', 'get_avatar' ) ) { |
… |
… |
if ( ! function_exists( 'get_avatar' ) ) : |
2762 | 2763 | $extra_attr .= "loading='{$loading}'"; |
2763 | 2764 | } |
2764 | 2765 | |
| 2766 | if ( isset( $args['decoding'] ) && in_array( $args['decoding'], array( 'async', 'sync', 'auto' ) ) && ! preg_match( '/\bdecoding\s*=/', $extra_attr ) ) { |
| 2767 | if ( ! empty( $extra_attr ) ) { |
| 2768 | $extra_attr .= ' '; |
| 2769 | } |
| 2770 | $extra_attr .= "decoding='{$args['decoding']}'"; |
| 2771 | } |
| 2772 | |
2765 | 2773 | $avatar = sprintf( |
2766 | 2774 | "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", |
2767 | 2775 | esc_attr( $args['alt'] ), |
diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
index 2781378c86..9921d6cf4f 100644
a
|
b
|
CAP; |
67 | 67 | <img src="pic.jpg" id='anId' alt="pic"/> |
68 | 68 | CAP; |
69 | 69 | $this->img_name = 'image.jpg'; |
70 | | $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name; |
| 70 | $this->img_url = WP_CONTENT_URL . '/uploads/' . $this->img_name; |
71 | 71 | $this->img_html = '<img src="' . $this->img_url . '"/>'; |
72 | 72 | $this->img_meta = array( |
73 | 73 | 'width' => 100, |
… |
… |
https://w.org</a>', |
430 | 430 | 'post_type' => 'attachment', |
431 | 431 | 'post_parent' => 0, |
432 | 432 | 'post_mime_type' => 'image/jpeg', |
433 | | 'guid' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-image.jpg', |
| 433 | 'guid' => WP_CONTENT_URL . '/uploads/test-image.jpg', |
434 | 434 | ) |
435 | 435 | ); |
436 | 436 | |
… |
… |
https://w.org</a>', |
524 | 524 | $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); |
525 | 525 | wp_update_attachment_metadata( $attachment_id, $metadata ); |
526 | 526 | $ids1[] = $attachment_id; |
527 | | $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| 527 | $ids1_srcs[] = WP_CONTENT_URL . '/uploads/' . "image$i.jpg"; |
528 | 528 | } |
529 | 529 | |
530 | 530 | $ids2 = array(); |
… |
… |
https://w.org</a>', |
541 | 541 | $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); |
542 | 542 | wp_update_attachment_metadata( $attachment_id, $metadata ); |
543 | 543 | $ids2[] = $attachment_id; |
544 | | $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| 544 | $ids2_srcs[] = WP_CONTENT_URL . '/uploads/' . "image$i.jpg"; |
545 | 545 | } |
546 | 546 | |
547 | 547 | $ids1_joined = implode( ',', $ids1 ); |
… |
… |
BLOB; |
605 | 605 | ) |
606 | 606 | ); |
607 | 607 | $expected_srcs = array( |
608 | | 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg', |
| 608 | WP_CONTENT_URL . '/uploads/test.jpg', |
609 | 609 | ); |
610 | 610 | |
611 | 611 | // Set the global $post context to the other post. |
… |
… |
BLOB; |
640 | 640 | ) |
641 | 641 | ); |
642 | 642 | $expected_srcs = array( |
643 | | 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg', |
| 643 | WP_CONTENT_URL . '/uploads/test.jpg', |
644 | 644 | ); |
645 | 645 | |
646 | 646 | $galleries = get_post_galleries( $post_id_two, false ); |
… |
… |
BLOB; |
674 | 674 | $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); |
675 | 675 | wp_update_attachment_metadata( $attachment_id, $metadata ); |
676 | 676 | $ids1[] = $attachment_id; |
677 | | $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| 677 | $ids1_srcs[] = WP_CONTENT_URL . '/uploads/' . "image$i.jpg"; |
678 | 678 | } |
679 | 679 | |
680 | 680 | $ids2 = array(); |
… |
… |
BLOB; |
691 | 691 | $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); |
692 | 692 | wp_update_attachment_metadata( $attachment_id, $metadata ); |
693 | 693 | $ids2[] = $attachment_id; |
694 | | $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| 694 | $ids2_srcs[] = WP_CONTENT_URL . '/uploads/' . "image$i.jpg"; |
695 | 695 | } |
696 | 696 | |
697 | 697 | $ids1_joined = implode( ',', $ids1 ); |
… |
… |
VIDEO; |
1087 | 1087 | ) |
1088 | 1088 | ); |
1089 | 1089 | |
1090 | | $image_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path; |
| 1090 | $image_url = WP_CONTENT_URL . '/uploads/' . $image_path; |
1091 | 1091 | $this->assertSame( $attachment_id, attachment_url_to_postid( $image_url ) ); |
1092 | 1092 | } |
1093 | 1093 | |
… |
… |
VIDEO; |
1105 | 1105 | ) |
1106 | 1106 | ); |
1107 | 1107 | |
1108 | | $image_url = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path; |
| 1108 | $image_url = set_url_scheme( WP_CONTENT_URL, 'https' ) . '/uploads/' . $image_path; |
1109 | 1109 | $this->assertSame( $attachment_id, attachment_url_to_postid( $image_url ) ); |
1110 | 1110 | } |
1111 | 1111 | |
… |
… |
VIDEO; |
1133 | 1133 | ) |
1134 | 1134 | ); |
1135 | 1135 | |
1136 | | $image_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path_upper_case; |
| 1136 | $image_url = WP_CONTENT_URL . '/uploads/' . $image_path_upper_case; |
1137 | 1137 | $this->assertSame( $attachment_id_upper_case, attachment_url_to_postid( $image_url ) ); |
1138 | 1138 | } |
1139 | 1139 | |
… |
… |
EOF; |
1370 | 1370 | function test_wp_get_attachment_image_defaults() { |
1371 | 1371 | $image = image_downsize( self::$large_id, 'thumbnail' ); |
1372 | 1372 | $expected = sprintf( |
1373 | | '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" />', |
| 1373 | '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" decoding="async" />', |
1374 | 1374 | $image[1], |
1375 | 1375 | $image[2], |
1376 | 1376 | $image[0] |
… |
… |
EOF; |
1408 | 1408 | |
1409 | 1409 | $image = image_downsize( self::$large_id, 'thumbnail' ); |
1410 | 1410 | $expected = sprintf( |
1411 | | '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="Some very clever alt text" loading="lazy" />', |
| 1411 | '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="Some very clever alt text" loading="lazy" decoding="async" />', |
1412 | 1412 | $image[1], |
1413 | 1413 | $image[2], |
1414 | 1414 | $image[0] |
… |
… |
EOF; |
1528 | 1528 | |
1529 | 1529 | $year_month = gmdate( 'Y/m' ); |
1530 | 1530 | $image_meta = wp_get_attachment_metadata( self::$large_id ); |
1531 | | $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; |
| 1531 | $uploads_dir_url = WP_CONTENT_URL . '/uploads/'; |
1532 | 1532 | |
1533 | 1533 | // Set up test cases for all expected size names. |
1534 | 1534 | $intermediates = array( 'medium', 'medium_large', 'large', 'full' ); |
… |
… |
EOF; |
1582 | 1582 | $id = self::factory()->attachment->create_upload_object( $filename ); |
1583 | 1583 | |
1584 | 1584 | $image_meta = wp_get_attachment_metadata( $id ); |
1585 | | $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; |
| 1585 | $uploads_dir_url = WP_CONTENT_URL . '/uploads/'; |
1586 | 1586 | |
1587 | 1587 | // Set up test cases for all expected size names. |
1588 | 1588 | $intermediates = array( 'medium', 'medium_large', 'large', 'full' ); |
… |
… |
EOF; |
1667 | 1667 | |
1668 | 1668 | $year_month = gmdate( 'Y/m' ); |
1669 | 1669 | $image_meta = wp_get_attachment_metadata( self::$large_id ); |
1670 | | $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; |
| 1670 | $uploads_dir_url = WP_CONTENT_URL . '/uploads/'; |
1671 | 1671 | |
1672 | 1672 | // Set up test cases for all expected size names. |
1673 | 1673 | $intermediates = array( 'medium', 'medium_large', 'large', 'full' ); |
… |
… |
EOF; |
1744 | 1744 | function test_wp_calculate_image_srcset_ratio_variance() { |
1745 | 1745 | // Mock data for this test. |
1746 | 1746 | $size_array = array( 218, 300 ); |
1747 | | $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x1055-218x300.png'; |
| 1747 | $image_src = WP_CONTENT_URL . '/uploads/2015/12/test-768x1055-218x300.png'; |
1748 | 1748 | $image_meta = array( |
1749 | 1749 | 'width' => 768, |
1750 | 1750 | 'height' => 1055, |
… |
… |
EOF; |
1777 | 1777 | ), |
1778 | 1778 | ); |
1779 | 1779 | |
1780 | | $uploads_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/'; |
| 1780 | $uploads_url = WP_CONTENT_URL . '/uploads/2015/12/'; |
1781 | 1781 | |
1782 | 1782 | $expected_srcset = $uploads_url . 'test-768x1055-218x300.png 218w, ' . |
1783 | 1783 | $uploads_url . 'test-768x1055-600x824.png 600w, ' . |
… |
… |
EOF; |
1793 | 1793 | function test_wp_calculate_image_srcset_include_src() { |
1794 | 1794 | // Mock data for this test. |
1795 | 1795 | $size_array = array( 2000, 1000 ); |
1796 | | $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png'; |
| 1796 | $image_src = WP_CONTENT_URL . '/uploads/2015/12/test.png'; |
1797 | 1797 | $image_meta = array( |
1798 | 1798 | 'width' => 2000, |
1799 | 1799 | 'height' => 1000, |
… |
… |
EOF; |
1826 | 1826 | ), |
1827 | 1827 | ); |
1828 | 1828 | |
1829 | | $uploads_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/'; |
| 1829 | $uploads_url = WP_CONTENT_URL . '/uploads/2015/12/'; |
1830 | 1830 | |
1831 | 1831 | $expected_srcset = $uploads_url . 'test.png 2000w, ' . |
1832 | 1832 | $uploads_url . 'test-300x150.png 300w, ' . |
… |
… |
EOF; |
1841 | 1841 | */ |
1842 | 1842 | function test_wp_calculate_image_srcset_corrupted_image_meta() { |
1843 | 1843 | $size_array = array( 300, 150 ); |
1844 | | $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png'; |
| 1844 | $image_src = WP_CONTENT_URL . '/uploads/2015/12/test-300x150.png'; |
1845 | 1845 | $image_meta = array( |
1846 | 1846 | 'width' => 1600, |
1847 | 1847 | 'height' => 800, |
… |
… |
EOF; |
1875 | 1875 | ); |
1876 | 1876 | |
1877 | 1877 | $srcset = array( |
1878 | | 300 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png 300w', |
1879 | | 768 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x384.png 768w', |
1880 | | 1024 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-1024x512.png 1024w', |
1881 | | 1600 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 1600w', |
| 1878 | 300 => WP_CONTENT_URL . '/uploads/2015/12/test-300x150.png 300w', |
| 1879 | 768 => WP_CONTENT_URL . '/uploads/2015/12/test-768x384.png 768w', |
| 1880 | 1024 => WP_CONTENT_URL . '/uploads/2015/12/test-1024x512.png 1024w', |
| 1881 | 1600 => WP_CONTENT_URL . '/uploads/2015/12/test.png 1600w', |
1882 | 1882 | ); |
1883 | 1883 | |
1884 | 1884 | // No sizes array. |
… |
… |
EOF; |
1915 | 1915 | */ |
1916 | 1916 | function test_wp_calculate_image_srcset_with_spaces_in_filenames() { |
1917 | 1917 | // Mock data for this test. |
1918 | | $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test image-300x150.png'; |
| 1918 | $image_src = WP_CONTENT_URL . '/uploads/2015/12/test image-300x150.png'; |
1919 | 1919 | $image_meta = array( |
1920 | 1920 | 'width' => 3000, |
1921 | 1921 | 'height' => 1500, |
… |
… |
EOF; |
1948 | 1948 | ), |
1949 | 1949 | ); |
1950 | 1950 | |
1951 | | $uploads_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/'; |
| 1951 | $uploads_url = WP_CONTENT_URL . '/uploads/2015/12/'; |
1952 | 1952 | |
1953 | 1953 | $expected_srcset = $uploads_url . 'test%20image-300x150.png 300w, ' . |
1954 | 1954 | $uploads_url . 'test%20image-768x384.png 768w, ' . |
… |
… |
EOF; |
1970 | 1970 | $srcset = wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ); |
1971 | 1971 | |
1972 | 1972 | $year_month = gmdate( 'Y/m' ); |
1973 | | $uploads_dir = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; |
| 1973 | $uploads_dir = WP_CONTENT_URL . '/uploads/'; |
1974 | 1974 | |
1975 | 1975 | // Set up test cases for all expected size names. |
1976 | 1976 | $intermediates = array( 'medium', 'medium_large', 'large', 'full' ); |
… |
… |
EOF; |
2144 | 2144 | $respimg_xhtml, |
2145 | 2145 | $respimg_html5 |
2146 | 2146 | ); |
| 2147 | $content_filtered = wp_img_tag_add_decoding_async_attr( $content_filtered ); |
2147 | 2148 | |
2148 | 2149 | // Do not add width, height, and loading. |
2149 | 2150 | add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); |
… |
… |
EOF; |
2169 | 2170 | function test_wp_filter_content_tags_srcset_sizes_wrong() { |
2170 | 2171 | $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); |
2171 | 2172 | $img = wp_img_tag_add_loading_attr( $img, 'test' ); |
| 2173 | $img = wp_img_tag_add_decoding_async_attr( $img ); |
2172 | 2174 | |
2173 | 2175 | // Replace the src URL. |
2174 | 2176 | $image_wrong_src = preg_replace( '|src="[^"]+"|', 'src="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/foo.jpg"', $img ); |
… |
… |
EOF; |
2183 | 2185 | // Generate HTML and add a dummy srcset attribute. |
2184 | 2186 | $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); |
2185 | 2187 | $img = wp_img_tag_add_loading_attr( $img, 'test' ); |
| 2188 | $img = wp_img_tag_add_decoding_async_attr( $img ); |
2186 | 2189 | $img = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $img ); |
2187 | 2190 | |
2188 | 2191 | // The content filter should return the image unchanged. |
… |
… |
EOF; |
2221 | 2224 | ), |
2222 | 2225 | ); |
2223 | 2226 | |
2224 | | $full_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file']; |
2225 | | $large_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['large']['file']; |
| 2227 | $full_src = WP_CONTENT_URL . '/uploads/' . $image_meta['file']; |
| 2228 | $large_src = WP_CONTENT_URL . '/uploads/' . $image_meta['sizes']['large']['file']; |
2226 | 2229 | |
2227 | 2230 | // Test with soft resized size array. |
2228 | 2231 | $size_array = array( 900, 450 ); |
… |
… |
EOF; |
2279 | 2282 | $respimg_https, |
2280 | 2283 | $respimg_relative |
2281 | 2284 | ); |
| 2285 | $expected = wp_img_tag_add_decoding_async_attr( $expected ); |
2282 | 2286 | |
2283 | 2287 | $actual = wp_filter_content_tags( $unfiltered ); |
2284 | 2288 | |
… |
… |
EOF; |
2314 | 2318 | ), |
2315 | 2319 | ); |
2316 | 2320 | |
| 2321 | $wp_content_path = wp_parse_url( WP_CONTENT_URL, PHP_URL_PATH ); |
| 2322 | |
2317 | 2323 | // Test using the large file size. |
2318 | 2324 | $size_array = array( 1024, 512 ); |
2319 | | $image_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['large']['file']; |
| 2325 | $image_url = 'http://' . WP_TESTS_DOMAIN . $wp_content_path . '/uploads/' . $image_meta['sizes']['large']['file']; |
2320 | 2326 | |
2321 | 2327 | $_SERVER['HTTPS'] = 'on'; |
2322 | 2328 | |
2323 | | $uploads_url = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; |
| 2329 | $uploads_url = 'https://' . WP_TESTS_DOMAIN . $wp_content_path . '/uploads/'; |
2324 | 2330 | |
2325 | 2331 | $expected = $uploads_url . 'test-1024x512.jpg 1024w, ' . |
2326 | 2332 | $uploads_url . 'test-300x150.jpg 300w, ' . |
… |
… |
EOF; |
2417 | 2423 | |
2418 | 2424 | $basename = wp_basename( self::$large_filename, '.jpg' ); |
2419 | 2425 | $year_month = gmdate( 'Y/m' ); |
2420 | | $uploads_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month . '/'; |
| 2426 | $uploads_url = WP_CONTENT_URL . '/uploads/' . $year_month . '/'; |
2421 | 2427 | |
2422 | 2428 | $expected = '<img width="999" height="999" ' . |
2423 | 2429 | 'src="' . $uploads_url . 'test-image-testsize-999x999.jpg" ' . |
2424 | 2430 | 'class="attachment-testsize size-testsize" alt="" loading="lazy" ' . |
2425 | 2431 | 'srcset="' . $uploads_url . 'test-image-testsize-999x999.jpg 999w, ' . $uploads_url . $basename . '-150x150.jpg 150w" ' . |
2426 | | 'sizes="(max-width: 999px) 100vw, 999px" />'; |
| 2432 | 'sizes="(max-width: 999px) 100vw, 999px" decoding="async" />'; |
2427 | 2433 | |
2428 | 2434 | $actual = wp_get_attachment_image( self::$large_id, 'testsize' ); |
2429 | 2435 | |
… |
… |
EOF; |
2728 | 2734 | %4$s'; |
2729 | 2735 | |
2730 | 2736 | $content_unfiltered = sprintf( $content, $img, $img_no_width_height, $img_no_width, $img_no_height ); |
2731 | | $content_filtered = sprintf( $content, $img, $respimg_no_width_height, $img_no_width, $img_no_height ); |
| 2737 | $content_filtered = wp_img_tag_add_decoding_async_attr( sprintf( $content, $img, $respimg_no_width_height, $img_no_width, $img_no_height ) ); |
2732 | 2738 | |
2733 | 2739 | // Do not add loading, srcset, and sizes. |
2734 | 2740 | add_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); |
… |
… |
EOF; |
2786 | 2792 | %8$s'; |
2787 | 2793 | |
2788 | 2794 | $content_unfiltered = sprintf( $content, $img, $img_xhtml, $img_html5, $img_eager, $img_no_width_height, $iframe, $iframe_eager, $iframe_no_width_height ); |
2789 | | $content_filtered = sprintf( $content, $lazy_img, $lazy_img_xhtml, $lazy_img_html5, $img_eager, $img_no_width_height, $lazy_iframe, $iframe_eager, $iframe_no_width_height ); |
| 2795 | $content_filtered = wp_img_tag_add_decoding_async_attr( sprintf( $content, $lazy_img, $lazy_img_xhtml, $lazy_img_html5, $img_eager, $img_no_width_height, $lazy_iframe, $iframe_eager, $iframe_no_width_height ) ); |
2790 | 2796 | |
2791 | 2797 | // Do not add width, height, srcset, and sizes. |
2792 | 2798 | add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); |
… |
… |
EOF; |
2815 | 2821 | %2$s'; |
2816 | 2822 | |
2817 | 2823 | $content_unfiltered = sprintf( $content, $img, $iframe ); |
2818 | | $content_filtered = sprintf( $content, $lazy_img, $lazy_iframe ); |
| 2824 | $content_filtered = sprintf( $content, wp_img_tag_add_decoding_async_attr( $lazy_img ), $lazy_iframe ); |
2819 | 2825 | |
2820 | 2826 | // Do not add srcset and sizes while testing. |
2821 | 2827 | add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); |
… |
… |
EOF; |
2833 | 2839 | * @ticket 50756 |
2834 | 2840 | */ |
2835 | 2841 | function test_wp_filter_content_tags_loading_lazy_opted_out() { |
2836 | | $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); |
| 2842 | $img = wp_img_tag_add_decoding_async_attr( get_image_tag( self::$large_id, '', '', '', 'medium' ) ); |
2837 | 2843 | $iframe = '<iframe src="https://www.example.com" width="640" height="360"></iframe>'; |
2838 | 2844 | |
2839 | 2845 | $content = ' |
… |
… |
EOF; |
3300 | 3306 | |
3301 | 3307 | // Following the threshold of 2, the first two content media elements should not be lazy-loaded. |
3302 | 3308 | $content_unfiltered = $img1 . $iframe1 . $img2 . $img3 . $iframe2; |
3303 | | $content_expected = $img1 . $iframe1 . $lazy_img2 . $lazy_img3 . $lazy_iframe2; |
| 3309 | $content_expected = wp_img_tag_add_decoding_async_attr( $img1 . $iframe1 . $lazy_img2 . $lazy_img3 . $lazy_iframe2 ); |
3304 | 3310 | |
3305 | 3311 | $wp_query = new WP_Query( array( 'post__in' => array( self::$post_ids['publish'] ) ) ); |
3306 | 3312 | $wp_the_query = $wp_query; |
diff --git a/tests/phpunit/tests/media/getAdjacentImageLink.php b/tests/phpunit/tests/media/getAdjacentImageLink.php
index 265c5d6bb2..db32b57bfa 100644
a
|
b
|
class Tests_Media_GetAdjacentImageLink extends WP_Test_Adjacent_Image_Link_TestC |
32 | 32 | 'when has previous link' => array( |
33 | 33 | 'current_attachment_index' => 3, |
34 | 34 | 'expected_attachment_index' => 2, |
35 | | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="http://example.org/wp-content/uploads/image2.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" /></a>', |
| 35 | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="' . WP_CONTENT_URL . '/uploads/image2.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" decoding="async" /></a>', |
36 | 36 | ), |
37 | 37 | 'with text when has previous link' => array( |
38 | 38 | 'current_attachment_index' => 3, |
… |
… |
class Tests_Media_GetAdjacentImageLink extends WP_Test_Adjacent_Image_Link_TestC |
43 | 43 | 'when has next link' => array( |
44 | 44 | 'current_attachment_index' => 4, |
45 | 45 | 'expected_attachment_index' => 5, |
46 | | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="http://example.org/wp-content/uploads/image5.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" /></a>', |
| 46 | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="' . WP_CONTENT_URL . '/uploads/image5.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" decoding="async" /></a>', |
47 | 47 | 'args' => array( 'prev' => false ), |
48 | 48 | ), |
49 | 49 | 'with text when has next link' => array( |
diff --git a/tests/phpunit/tests/media/getNextImageLink.php b/tests/phpunit/tests/media/getNextImageLink.php
index feb5fdbdf7..dbec6f5f2c 100644
a
|
b
|
class Tests_Media_GetNextImageLink extends WP_Test_Adjacent_Image_Link_TestCase |
31 | 31 | 'when has next link' => array( |
32 | 32 | 'current_attachment_index' => 4, |
33 | 33 | 'expected_attachment_index' => 5, |
34 | | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="http://example.org/wp-content/uploads/image5.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" /></a>', |
| 34 | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="' . WP_CONTENT_URL . '/uploads/image5.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" decoding="async" /></a>', |
35 | 35 | ), |
36 | 36 | 'with text when has next link' => array( |
37 | 37 | 'current_attachment_index' => 4, |
diff --git a/tests/phpunit/tests/media/getPreviousImageLink.php b/tests/phpunit/tests/media/getPreviousImageLink.php
index 61763ee3a2..ba06ca9b2d 100644
a
|
b
|
class Tests_Media_GetPreviousImageLink extends WP_Test_Adjacent_Image_Link_TestC |
31 | 31 | 'when has previous link' => array( |
32 | 32 | 'current_attachment_index' => 3, |
33 | 33 | 'expected_attachment_index' => 2, |
34 | | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="http://example.org/wp-content/uploads/image2.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" /></a>', |
| 34 | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="' . WP_CONTENT_URL . '/uploads/image2.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" decoding="async" /></a>', |
35 | 35 | ), |
36 | 36 | 'with text when has previous link' => array( |
37 | 37 | 'current_attachment_index' => 3, |
diff --git a/tests/phpunit/tests/media/nextImageLink.php b/tests/phpunit/tests/media/nextImageLink.php
index f3ba340b7f..352a842388 100644
a
|
b
|
class Tests_Media_NextImageLink extends WP_Test_Adjacent_Image_Link_TestCase { |
30 | 30 | 'when has next link' => array( |
31 | 31 | 'current_attachment_index' => 4, |
32 | 32 | 'expected_attachment_index' => 5, |
33 | | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="http://example.org/wp-content/uploads/image5.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" /></a>', |
| 33 | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="' . WP_CONTENT_URL . '/uploads/image5.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" decoding="async" /></a>', |
34 | 34 | ), |
35 | 35 | 'with text when has next link' => array( |
36 | 36 | 'current_attachment_index' => 4, |
diff --git a/tests/phpunit/tests/media/previousImageLink.php b/tests/phpunit/tests/media/previousImageLink.php
index 769d029d89..ffd6309ece 100644
a
|
b
|
class Tests_Media_PreviousImageLink extends WP_Test_Adjacent_Image_Link_TestCase |
30 | 30 | 'when has previous link' => array( |
31 | 31 | 'current_attachment_index' => 3, |
32 | 32 | 'expected_attachment_index' => 2, |
33 | | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="http://example.org/wp-content/uploads/image2.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" /></a>', |
| 33 | 'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="' . WP_CONTENT_URL . '/uploads/image2.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" decoding="async" /></a>', |
34 | 34 | ), |
35 | 35 | 'with text when has previous link' => array( |
36 | 36 | 'current_attachment_index' => 3, |