Media: Some documentation and test improvements for `wp_img_tag_add_decoding_attr()`:

* Add a `@since` note for the `decoding` attribute in `wp_get_attachment_image()`.
* Adjust `wp_img_tag_add_decoding_attr()` DocBlocks per the documentation standards.
* Wrap some long `sprintf()` calls in unit tests for better readability. In at least one case, `the_content` was unnecessarily passed to `sprintf()` as an extra (unused) parameter.

Follow-up to [53480].

See #53232.
Built from https://develop.svn.wordpress.org/trunk@53481


git-svn-id: http://core.svn.wordpress.org/trunk@53070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-06-09 16:21:14 +00:00
parent b8e44627c8
commit 558cd4c353
2 changed files with 9 additions and 6 deletions

View File

@ -1003,6 +1003,7 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
* @since 2.5.0 * @since 2.5.0
* @since 4.4.0 The `$srcset` and `$sizes` attributes were added. * @since 4.4.0 The `$srcset` and `$sizes` attributes were added.
* @since 5.5.0 The `$loading` attribute was added. * @since 5.5.0 The `$loading` attribute was added.
* @since 6.1.0 The `$decoding` attribute was added.
* *
* @param int $attachment_id Image attachment ID. * @param int $attachment_id Image attachment ID.
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
@ -1943,7 +1944,7 @@ function wp_img_tag_add_loading_attr( $image, $context ) {
} }
/** /**
* Add `decoding` attribute to an `img` HTML tag. * Adds `decoding` attribute to an `img` HTML tag.
* *
* The `decoding` attribute allows developers to indicate whether the * The `decoding` attribute allows developers to indicate whether the
* browser can decode the image off the main thread (`async`), on the * browser can decode the image off the main thread (`async`), on the
@ -1968,13 +1969,15 @@ function wp_img_tag_add_decoding_attr( $image, $context ) {
* *
* @since 6.1.0 * @since 6.1.0
* *
* @param string|false|null $value The `decoding` attribute value. Returning a falsey value will result in * @param string|false|null $value The `decoding` attribute value. Returning a falsey value
* the attribute being omitted for the image. Otherwise, it may be: * will result in the attribute being omitted for the image.
* 'async' (default), 'sync', or 'auto'. * Otherwise, it may be: 'async' (default), 'sync', or 'auto'.
* @param string $image The HTML `img` tag to be filtered. * @param string $image The HTML `img` tag to be filtered.
* @param string $context Additional context about how the function was called or where the img tag is. * @param string $context Additional context about how the function was called
* or where the img tag is.
*/ */
$value = apply_filters( 'wp_img_tag_add_decoding_attr', 'async', $image, $context ); $value = apply_filters( 'wp_img_tag_add_decoding_attr', 'async', $image, $context );
if ( in_array( $value, array( 'async', 'sync', 'auto' ), true ) ) { if ( in_array( $value, array( 'async', 'sync', 'auto' ), true ) ) {
$image = str_replace( '<img ', '<img decoding="' . esc_attr( $value ) . '" ', $image ); $image = str_replace( '<img ', '<img decoding="' . esc_attr( $value ) . '" ', $image );
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.1-alpha-53480'; $wp_version = '6.1-alpha-53481';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.