Changeset 53480 for trunk/src/wp-includes/media.php
- Timestamp:
- 06/09/2022 05:29:57 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r53149 r53480 1012 1012 * Optional. Attributes for the image markup. 1013 1013 * 1014 * @type string $src Image attachment URL. 1015 * @type string $class CSS class name or space-separated list of classes. 1016 * Default `attachment-$size_class size-$size_class`, 1017 * where `$size_class` is the image size being requested. 1018 * @type string $alt Image description for the alt attribute. 1019 * @type string $srcset The 'srcset' attribute value. 1020 * @type string $sizes The 'sizes' attribute value. 1021 * @type string|false $loading The 'loading' attribute value. Passing a value of false 1022 * will result in the attribute being omitted for the image. 1023 * Defaults to 'lazy', depending on wp_lazy_loading_enabled(). 1014 * @type string $src Image attachment URL. 1015 * @type string $class CSS class name or space-separated list of classes. 1016 * Default `attachment-$size_class size-$size_class`, 1017 * where `$size_class` is the image size being requested. 1018 * @type string $alt Image description for the alt attribute. 1019 * @type string $srcset The 'srcset' attribute value. 1020 * @type string $sizes The 'sizes' attribute value. 1021 * @type string|false $loading The 'loading' attribute value. Passing a value of false 1022 * will result in the attribute being omitted for the image. 1023 * Defaults to 'lazy', depending on wp_lazy_loading_enabled(). 1024 * @type string $decoding The 'decoding' attribute value. Possible values are 1025 * 'async' (default), 'sync', or 'auto'. 1024 1026 * } 1025 1027 * @return string HTML img element or empty string on failure. … … 1041 1043 1042 1044 $default_attr = array( 1043 'src' => $src, 1044 'class' => "attachment-$size_class size-$size_class", 1045 'alt' => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ), 1045 'src' => $src, 1046 'class' => "attachment-$size_class size-$size_class", 1047 'alt' => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ), 1048 'decoding' => 'async', 1046 1049 ); 1047 1050 … … 1844 1847 } 1845 1848 1849 // Add 'decoding=async' attribute unless a 'decoding' attribute is already present. 1850 if ( ! str_contains( $filtered_image, ' decoding=' ) ) { 1851 $filtered_image = wp_img_tag_add_decoding_attr( $filtered_image, $context ); 1852 } 1853 1846 1854 /** 1847 1855 * Filters an img tag within the content for a given context. … … 1930 1938 1931 1939 return str_replace( '<img', '<img loading="' . esc_attr( $value ) . '"', $image ); 1940 } 1941 1942 return $image; 1943 } 1944 1945 /** 1946 * Add `decoding` attribute to an `img` HTML tag. 1947 * 1948 * The `decoding` attribute allows developers to indicate whether the 1949 * browser can decode the image off the main thread (`async`), on the 1950 * main thread (`sync`) or as determined by the browser (`auto`). 1951 * 1952 * By default WordPress adds `decoding="async"` to images but developers 1953 * can use the {@see 'wp_img_tag_add_decoding_attr'} filter to modify this 1954 * to remove the attribute or set it to another accepted value. 1955 * 1956 * @since 6.1.0 1957 * 1958 * @param string $image The HTML `img` tag where the attribute should be added. 1959 * @param string $context Additional context to pass to the filters. 1960 * 1961 * @return string Converted `img` tag with `decoding` attribute added. 1962 */ 1963 function wp_img_tag_add_decoding_attr( $image, $context ) { 1964 /** 1965 * Filters the `decoding` attribute value to add to an image. Default `async`. 1966 * 1967 * Returning a falsey value will omit the attribute. 1968 * 1969 * @since 6.1.0 1970 * 1971 * @param string|false|null $value The `decoding` attribute value. Returning a falsey value will result in 1972 * the attribute being omitted for the image. Otherwise, it may be: 1973 * 'async' (default), 'sync', or 'auto'. 1974 * @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 */ 1977 $value = apply_filters( 'wp_img_tag_add_decoding_attr', 'async', $image, $context ); 1978 if ( in_array( $value, array( 'async', 'sync', 'auto' ), true ) ) { 1979 $image = str_replace( '<img ', '<img decoding="' . esc_attr( $value ) . '" ', $image ); 1932 1980 } 1933 1981
Note: See TracChangeset
for help on using the changeset viewer.