Changeset 53481
- Timestamp:
- 06/09/2022 04:19:39 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r53480 r53481 1004 1004 * @since 4.4.0 The `$srcset` and `$sizes` attributes were added. 1005 1005 * @since 5.5.0 The `$loading` attribute was added. 1006 * @since 6.1.0 The `$decoding` attribute was added. 1006 1007 * 1007 1008 * @param int $attachment_id Image attachment ID. … … 1944 1945 1945 1946 /** 1946 * Add `decoding` attribute to an `img` HTML tag.1947 * Adds `decoding` attribute to an `img` HTML tag. 1947 1948 * 1948 1949 * The `decoding` attribute allows developers to indicate whether the … … 1969 1970 * @since 6.1.0 1970 1971 * 1971 * @param string|false|null $value The `decoding` attribute value. Returning a falsey value will result in1972 * the attribute being omitted for the image. Otherwise, it may be:1973 * 'async' (default), 'sync', or 'auto'.1972 * @param string|false|null $value The `decoding` attribute value. Returning a falsey value 1973 * will result in the attribute being omitted for the image. 1974 * Otherwise, it may be: 'async' (default), 'sync', or 'auto'. 1974 1975 * @param string $image The HTML `img` tag to be filtered. 1975 * @param string $context Additional context about how the function was called or where the img tag is. 1976 * @param string $context Additional context about how the function was called 1977 * or where the img tag is. 1976 1978 */ 1977 1979 $value = apply_filters( 'wp_img_tag_add_decoding_attr', 'async', $image, $context ); 1980 1978 1981 if ( in_array( $value, array( 'async', 'sync', 'auto' ), true ) ) { 1979 1982 $image = str_replace( '<img ', '<img decoding="' . esc_attr( $value ) . '" ', $image ); -
trunk/tests/phpunit/tests/media.php
r53480 r53481 2531 2531 2532 2532 $html = '<img src="%1$s" alt="" width="%2$d" height="%3$d" class="align%4$s size-medium wp-image-%5$d" />'; 2533 $expected = sprintf( $html, $attachment[0], $attachment[1], $attachment[2], $align, $id ); 2533 $expected = sprintf( 2534 $html, 2535 $attachment[0], 2536 $attachment[1], 2537 $attachment[2], 2538 $align, 2539 $id 2540 ); 2534 2541 2535 2542 $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) ); … … 2557 2564 $html = '[caption id="attachment_%9$d" align="align%7$s" width="%5$d"]' . $html . ' %10$s[/caption]'; 2558 2565 2559 $expected = sprintf( $html, $url, 'attachment wp-att-' . $id, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id, $caption ); 2566 $expected = sprintf( 2567 $html, 2568 $url, 2569 'attachment wp-att-' . $id, 2570 $attachment[0], 2571 $alt, 2572 $attachment[1], 2573 $attachment[2], 2574 $align, 2575 $size, 2576 $id, 2577 $caption 2578 ); 2560 2579 2561 2580 $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) ); … … 2580 2599 $html = '<a href="%1$s"><img src="%2$s" alt="%3$s" width="%4$d" height="%5$d" class="align%6$s size-%7$s wp-image-%8$d" /></a>'; 2581 2600 2582 $expected = sprintf( $html, $url, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id ); 2601 $expected = sprintf( 2602 $html, 2603 $url, 2604 $attachment[0], 2605 $alt, 2606 $attachment[1], 2607 $attachment[2], 2608 $align, 2609 $size, 2610 $id 2611 ); 2583 2612 2584 2613 $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) ); … … 2914 2943 %4$s'; 2915 2944 2916 $content_unfiltered = sprintf( $content, $img, $img_no_width_height, $img_no_width, $img_no_height ); 2917 $content_filtered = wp_img_tag_add_decoding_attr( sprintf( $content, $img, $respimg_no_width_height, $img_no_width, $img_no_height ), 'the_content' ); 2945 $content_unfiltered = sprintf( 2946 $content, 2947 $img, 2948 $img_no_width_height, 2949 $img_no_width, 2950 $img_no_height 2951 ); 2952 2953 $content_filtered = sprintf( 2954 $content, 2955 $img, 2956 $respimg_no_width_height, 2957 $img_no_width, 2958 $img_no_height 2959 ); 2960 $content_filtered = wp_img_tag_add_decoding_attr( $content_filtered, 'the_content' ); 2918 2961 2919 2962 // Do not add loading, srcset, and sizes. … … 2972 3015 %8$s'; 2973 3016 2974 $content_unfiltered = sprintf( $content, $img, $img_xhtml, $img_html5, $img_eager, $img_no_width_height, $iframe, $iframe_eager, $iframe_no_width_height ); 2975 $content_filtered = wp_img_tag_add_decoding_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 ), 'the_content' ); 3017 $content_unfiltered = sprintf( 3018 $content, 3019 $img, 3020 $img_xhtml, 3021 $img_html5, 3022 $img_eager, 3023 $img_no_width_height, 3024 $iframe, 3025 $iframe_eager, 3026 $iframe_no_width_height 3027 ); 3028 3029 $content_filtered = sprintf( 3030 $content, 3031 $lazy_img, 3032 $lazy_img_xhtml, 3033 $lazy_img_html5, 3034 $img_eager, 3035 $img_no_width_height, 3036 $lazy_iframe, 3037 $iframe_eager, 3038 $iframe_no_width_height 3039 ); 3040 $content_filtered = wp_img_tag_add_decoding_attr( $content_filtered, 'the_content' ); 2976 3041 2977 3042 // Do not add width, height, srcset, and sizes. … … 2992 3057 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); 2993 3058 $lazy_img = wp_img_tag_add_loading_attr( $img, 'test' ); 3059 $lazy_img = wp_img_tag_add_decoding_attr( $lazy_img, 'the_content' ); 2994 3060 $iframe = '<iframe src="https://www.example.com" width="640" height="360"></iframe>'; 2995 3061 $lazy_iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' ); … … 3002 3068 3003 3069 $content_unfiltered = sprintf( $content, $img, $iframe ); 3004 $content_filtered = sprintf( $content, wp_img_tag_add_decoding_attr( $lazy_img, 'the_content' ), $lazy_iframe, 'the_content');3070 $content_filtered = sprintf( $content, $lazy_img, $lazy_iframe ); 3005 3071 3006 3072 // Do not add srcset and sizes while testing. … … 3020 3086 */ 3021 3087 public function test_wp_filter_content_tags_loading_lazy_opted_out() { 3022 $img = wp_img_tag_add_decoding_attr( get_image_tag( self::$large_id, '', '', '', 'medium' ), 'the_content' ); 3088 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); 3089 $img = wp_img_tag_add_decoding_attr( $img, 'the_content' ); 3023 3090 $iframe = '<iframe src="https://www.example.com" width="640" height="360"></iframe>'; 3024 3091 … … 3484 3551 // Following the threshold of 2, the first two content media elements should not be lazy-loaded. 3485 3552 $content_unfiltered = $img1 . $iframe1 . $img2 . $img3 . $iframe2; 3486 $content_expected = wp_img_tag_add_decoding_attr( $img1 . $iframe1 . $lazy_img2 . $lazy_img3 . $lazy_iframe2, 'the_content' ); 3553 $content_expected = $img1 . $iframe1 . $lazy_img2 . $lazy_img3 . $lazy_iframe2; 3554 $content_expected = wp_img_tag_add_decoding_attr( $content_expected, 'the_content' ); 3487 3555 3488 3556 $wp_query = new WP_Query( array( 'post__in' => array( self::$post_ids['publish'] ) ) );
Note: See TracChangeset
for help on using the changeset viewer.