<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[53480] trunk: Media: Add `decoding="async"` to image attributes.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/53480">53480</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/53480","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>peterwilsoncc</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-06-09 05:29:57 +0000 (Thu, 09 Jun 2022)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Media: Add `decoding="async"` to image attributes.

Dynamically add `decoding="async"` to image tags on the front end of a site to instruct browsers to download them in parallel.

Modifies `wp_get_attachment_image()`, `get_avatar()` to include the attribute by default. Modifies `wp_filter_content_tags()` to add the attribute during the front-end render of the site.

Introduces `wp_img_tag_add_decoding_attr()` to take an image tag and modify it to include the attribute. Introduces the filter `wp_img_tag_add_decoding_attr` used to define the default value for the attribute.

Props adamsilverstein, ayeshrajans, costdev, flixos90, hellofromtonya, isaumya, michaelbourne, mihai2u, mitogh, sergiomdgomes, spacedmonkey, westonruter, peterwilsoncc.
Fixes <a href="https://core.trac.wordpress.org/ticket/53232">#53232</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
<li><a href="#trunksrcwpincludespluggablephp">trunk/src/wp-includes/pluggable.php</a></li>
<li><a href="#trunktestsphpunittestsavatarphp">trunk/tests/phpunit/tests/avatar.php</a></li>
<li><a href="#trunktestsphpunittestsmediagetAdjacentImageLinkphp">trunk/tests/phpunit/tests/media/getAdjacentImageLink.php</a></li>
<li><a href="#trunktestsphpunittestsmediagetNextImageLinkphp">trunk/tests/phpunit/tests/media/getNextImageLink.php</a></li>
<li><a href="#trunktestsphpunittestsmediagetPreviousImageLinkphp">trunk/tests/phpunit/tests/media/getPreviousImageLink.php</a></li>
<li><a href="#trunktestsphpunittestsmedianextImageLinkphp">trunk/tests/phpunit/tests/media/nextImageLink.php</a></li>
<li><a href="#trunktestsphpunittestsmediapreviousImageLinkphp">trunk/tests/phpunit/tests/media/previousImageLink.php</a></li>
<li><a href="#trunktestsphpunittestsmediaphp">trunk/tests/phpunit/tests/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/media.php   2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/src/wp-includes/media.php     2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1011,16 +1011,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string|array $attr {
</span><span class="cx" style="display: block; padding: 0 10px">  *     Optional. Attributes for the image markup.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *     @type string       $src     Image attachment URL.
- *     @type string       $class   CSS class name or space-separated list of classes.
- *                                 Default `attachment-$size_class size-$size_class`,
- *                                 where `$size_class` is the image size being requested.
- *     @type string       $alt     Image description for the alt attribute.
- *     @type string       $srcset  The 'srcset' attribute value.
- *     @type string       $sizes   The 'sizes' attribute value.
- *     @type string|false $loading The 'loading' attribute value. Passing a value of false
- *                                 will result in the attribute being omitted for the image.
- *                                 Defaults to 'lazy', depending on wp_lazy_loading_enabled().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *     @type string       $src      Image attachment URL.
+ *     @type string       $class    CSS class name or space-separated list of classes.
+ *                                  Default `attachment-$size_class size-$size_class`,
+ *                                  where `$size_class` is the image size being requested.
+ *     @type string       $alt      Image description for the alt attribute.
+ *     @type string       $srcset   The 'srcset' attribute value.
+ *     @type string       $sizes    The 'sizes' attribute value.
+ *     @type string|false $loading  The 'loading' attribute value. Passing a value of false
+ *                                  will result in the attribute being omitted for the image.
+ *                                  Defaults to 'lazy', depending on wp_lazy_loading_enabled().
+ *     @type string       $decoding The 'decoding' attribute value. Possible values are
+ *                                  'async' (default), 'sync', or 'auto'.
</ins><span class="cx" style="display: block; padding: 0 10px">  * }
</span><span class="cx" style="display: block; padding: 0 10px">  * @return string HTML img element or empty string on failure.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1040,9 +1042,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $default_attr = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'src'   => $src,
-                       'class' => "attachment-$size_class size-$size_class",
-                       'alt'   => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'src'      => $src,
+                       'class'    => "attachment-$size_class size-$size_class",
+                       'alt'      => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
+                       'decoding' => 'async',
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Add `loading` attribute.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1843,6 +1846,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                $filtered_image = wp_img_tag_add_loading_attr( $filtered_image, $context );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        // Add 'decoding=async' attribute unless a 'decoding' attribute is already present.
+                       if ( ! str_contains( $filtered_image, ' decoding=' ) ) {
+                               $filtered_image = wp_img_tag_add_decoding_attr( $filtered_image, $context );
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         /**
</span><span class="cx" style="display: block; padding: 0 10px">                         * Filters an img tag within the content for a given context.
</span><span class="cx" style="display: block; padding: 0 10px">                         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1935,6 +1943,46 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Add `decoding` attribute to an `img` HTML tag.
+ *
+ * The `decoding` attribute allows developers to indicate whether the
+ * browser can decode the image off the main thread (`async`), on the
+ * main thread (`sync`) or as determined by the browser (`auto`).
+ *
+ * By default WordPress adds `decoding="async"` to images but developers
+ * can use the {@see 'wp_img_tag_add_decoding_attr'} filter to modify this
+ * to remove the attribute or set it to another accepted value.
+ *
+ * @since 6.1.0
+ *
+ * @param string $image   The HTML `img` tag where the attribute should be added.
+ * @param string $context Additional context to pass to the filters.
+ *
+ * @return string Converted `img` tag with `decoding` attribute added.
+ */
+function wp_img_tag_add_decoding_attr( $image, $context ) {
+       /**
+        * Filters the `decoding` attribute value to add to an image. Default `async`.
+        *
+        * Returning a falsey value will omit the attribute.
+        *
+        * @since 6.1.0
+        *
+        * @param string|false|null $value   The `decoding` attribute value. Returning a falsey value will result in
+        *                                   the attribute being omitted for the image. Otherwise, it may be:
+        *                                   'async' (default), 'sync', or 'auto'.
+        * @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.
+        */
+       $value = apply_filters( 'wp_img_tag_add_decoding_attr', 'async', $image, $context );
+       if ( in_array( $value, array( 'async', 'sync', 'auto' ), true ) ) {
+               $image = str_replace( '<img ', '<img decoding="' . esc_attr( $value ) . '" ', $image );
+       }
+
+       return $image;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Adds `width` and `height` attributes to an `img` HTML tag.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 5.5.0
</span></span></pre></div>
<a id="trunksrcwpincludespluggablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/pluggable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/pluggable.php       2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/src/wp-includes/pluggable.php 2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2764,6 +2764,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'force_display' => false,
</span><span class="cx" style="display: block; padding: 0 10px">                        'loading'       => null,
</span><span class="cx" style="display: block; padding: 0 10px">                        'extra_attr'    => '',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'decoding'      => 'async',
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( wp_lazy_loading_enabled( 'img', 'get_avatar' ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2851,6 +2852,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $extra_attr .= "loading='{$loading}'";
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( in_array( $args['decoding'], array( 'async', 'sync', 'auto' ) ) && ! preg_match( '/\bdecoding\s*=/', $extra_attr ) ) {
+                       if ( ! empty( $extra_attr ) ) {
+                               $extra_attr .= ' ';
+                       }
+                       $extra_attr .= "decoding='{$args['decoding']}'";
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $avatar = sprintf(
</span><span class="cx" style="display: block; padding: 0 10px">                        "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>",
</span><span class="cx" style="display: block; padding: 0 10px">                        esc_attr( $args['alt'] ),
</span></span></pre></div>
<a id="trunktestsphpunittestsavatarphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/avatar.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/avatar.php      2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/tests/phpunit/tests/avatar.php        2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -169,7 +169,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_avatar() {
</span><span class="cx" style="display: block; padding: 0 10px">                $img = get_avatar( 1 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertSame( preg_match( "|^<img alt='[^']*' src='[^']*' srcset='[^']*' class='[^']*' height='[^']*' width='[^']*' loading='lazy'/>$|", $img ), 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( preg_match( "|^<img alt='[^']*' src='[^']*' srcset='[^']*' class='[^']*' height='[^']*' width='[^']*' loading='lazy' decoding='async'/>$|", $img ), 1 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_avatar_size() {
</span></span></pre></div>
<a id="trunktestsphpunittestsmediagetAdjacentImageLinkphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/media/getAdjacentImageLink.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/media/getAdjacentImageLink.php  2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/tests/phpunit/tests/media/getAdjacentImageLink.php    2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -32,7 +32,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'when has previous link'           => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 3,
</span><span class="cx" style="display: block; padding: 0 10px">                                'expected_attachment_index' => 2,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                '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>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         '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="" decoding="async" loading="lazy" /></a>',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'with text when has previous link' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 3,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -43,7 +43,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'when has next link'               => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 4,
</span><span class="cx" style="display: block; padding: 0 10px">                                'expected_attachment_index' => 5,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                '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>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         '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="" decoding="async" loading="lazy" /></a>',
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'args'                      => array( 'prev' => false ),
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'with text when has next link'     => array(
</span></span></pre></div>
<a id="trunktestsphpunittestsmediagetNextImageLinkphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/media/getNextImageLink.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/media/getNextImageLink.php      2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/tests/phpunit/tests/media/getNextImageLink.php        2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -31,7 +31,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'when has next link'           => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 4,
</span><span class="cx" style="display: block; padding: 0 10px">                                'expected_attachment_index' => 5,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                '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>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         '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="" decoding="async" loading="lazy" /></a>',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'with text when has next link' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 4,
</span></span></pre></div>
<a id="trunktestsphpunittestsmediagetPreviousImageLinkphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/media/getPreviousImageLink.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/media/getPreviousImageLink.php  2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/tests/phpunit/tests/media/getPreviousImageLink.php    2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -31,7 +31,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'when has previous link'           => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 3,
</span><span class="cx" style="display: block; padding: 0 10px">                                'expected_attachment_index' => 2,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                '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>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         '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="" decoding="async" loading="lazy" /></a>',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'with text when has previous link' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 3,
</span></span></pre></div>
<a id="trunktestsphpunittestsmedianextImageLinkphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/media/nextImageLink.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/media/nextImageLink.php 2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/tests/phpunit/tests/media/nextImageLink.php   2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,7 +30,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'when has next link'           => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 4,
</span><span class="cx" style="display: block; padding: 0 10px">                                'expected_attachment_index' => 5,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                '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>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         '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="" decoding="async" loading="lazy" /></a>',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'with text when has next link' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 4,
</span></span></pre></div>
<a id="trunktestsphpunittestsmediapreviousImageLinkphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/media/previousImageLink.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/media/previousImageLink.php     2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/tests/phpunit/tests/media/previousImageLink.php       2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,7 +30,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'when has previous link'           => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 3,
</span><span class="cx" style="display: block; padding: 0 10px">                                'expected_attachment_index' => 2,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                '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>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         '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="" decoding="async" loading="lazy" /></a>',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'with text when has previous link' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'current_attachment_index'  => 3,
</span></span></pre></div>
<a id="trunktestsphpunittestsmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/media.php       2022-06-08 13:17:27 UTC (rev 53479)
+++ trunk/tests/phpunit/tests/media.php 2022-06-09 05:29:57 UTC (rev 53480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1474,7 +1474,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_get_attachment_image_defaults() {
</span><span class="cx" style="display: block; padding: 0 10px">                $image    = image_downsize( self::$large_id, 'thumbnail' );
</span><span class="cx" style="display: block; padding: 0 10px">                $expected = sprintf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" />',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="" decoding="async" loading="lazy" />',
</ins><span class="cx" style="display: block; padding: 0 10px">                         $image[1],
</span><span class="cx" style="display: block; padding: 0 10px">                        $image[2],
</span><span class="cx" style="display: block; padding: 0 10px">                        $image[0]
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1512,7 +1512,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $image    = image_downsize( self::$large_id, 'thumbnail' );
</span><span class="cx" style="display: block; padding: 0 10px">                $expected = sprintf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="Some very clever alt text" loading="lazy" />',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="Some very clever alt text" decoding="async" loading="lazy" />',
</ins><span class="cx" style="display: block; padding: 0 10px">                         $image[1],
</span><span class="cx" style="display: block; padding: 0 10px">                        $image[2],
</span><span class="cx" style="display: block; padding: 0 10px">                        $image[0]
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2247,6 +2247,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $respimg_xhtml,
</span><span class="cx" style="display: block; padding: 0 10px">                        $respimg_html5
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $content_filtered = wp_img_tag_add_decoding_attr( $content_filtered, 'the_content' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Do not add width, height, and loading.
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2272,6 +2273,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_filter_content_tags_srcset_sizes_wrong() {
</span><span class="cx" style="display: block; padding: 0 10px">                $img = get_image_tag( self::$large_id, '', '', '', 'medium' );
</span><span class="cx" style="display: block; padding: 0 10px">                $img = wp_img_tag_add_loading_attr( $img, 'test' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $img = wp_img_tag_add_decoding_attr( $img, 'the_content' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Replace the src URL.
</span><span class="cx" style="display: block; padding: 0 10px">                $image_wrong_src = preg_replace( '|src="[^"]+"|', 'src="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/foo.jpg"', $img );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2286,6 +2288,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Generate HTML and add a dummy srcset attribute.
</span><span class="cx" style="display: block; padding: 0 10px">                $img = get_image_tag( self::$large_id, '', '', '', 'medium' );
</span><span class="cx" style="display: block; padding: 0 10px">                $img = wp_img_tag_add_loading_attr( $img, 'test' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $img = wp_img_tag_add_decoding_attr( $img, 'the_content' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $img = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $img );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // The content filter should return the image unchanged.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2333,7 +2336,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_filter_content_tags_filter_with_identical_image_tags_custom_attributes() {
</span><span class="cx" style="display: block; padding: 0 10px">                $img     = get_image_tag( self::$large_id, '', '', '', 'large' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $img     = str_replace( '<img ', '<img srcset="custom" sizes="custom" loading="custom" ', $img );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $img     = str_replace( '<img ', '<img srcset="custom" sizes="custom" loading="custom" decoding="custom"', $img );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $content = "$img\n$img";
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2358,6 +2361,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter(
</span><span class="cx" style="display: block; padding: 0 10px">                        'wp_content_img_tag',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2460,6 +2464,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $respimg_https,
</span><span class="cx" style="display: block; padding: 0 10px">                        $respimg_relative
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $expected = wp_img_tag_add_decoding_attr( $expected, 'the_content' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $actual = wp_filter_content_tags( $unfiltered );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2602,7 +2607,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $expected = '<img width="999" height="999" ' .
</span><span class="cx" style="display: block; padding: 0 10px">                        'src="' . $uploads_url . 'test-image-testsize-999x999.jpg" ' .
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'class="attachment-testsize size-testsize" alt="" loading="lazy" ' .
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'class="attachment-testsize size-testsize" alt="" decoding="async" loading="lazy" ' .
</ins><span class="cx" style="display: block; padding: 0 10px">                         'srcset="' . $uploads_url . 'test-image-testsize-999x999.jpg 999w, ' . $uploads_url . $basename . '-150x150.jpg 150w" ' .
</span><span class="cx" style="display: block; padding: 0 10px">                        'sizes="(max-width: 999px) 100vw, 999px" />';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2909,7 +2914,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        %4$s';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $content_unfiltered = sprintf( $content, $img, $img_no_width_height, $img_no_width, $img_no_height );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $content_filtered   = sprintf( $content, $img, $respimg_no_width_height, $img_no_width, $img_no_height );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $content_filtered   = wp_img_tag_add_decoding_attr( sprintf( $content, $img, $respimg_no_width_height, $img_no_width, $img_no_height ), 'the_content' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Do not add loading, srcset, and sizes.
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2967,7 +2972,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        %8$s';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $content_unfiltered = sprintf( $content, $img, $img_xhtml, $img_html5, $img_eager, $img_no_width_height, $iframe, $iframe_eager, $iframe_no_width_height );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $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' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Do not add width, height, srcset, and sizes.
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2996,7 +3001,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        %2$s';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $content_unfiltered = sprintf( $content, $img, $iframe );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $content_filtered   = sprintf( $content, $lazy_img, $lazy_iframe );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $content_filtered   = sprintf( $content, wp_img_tag_add_decoding_attr( $lazy_img, 'the_content' ), $lazy_iframe, 'the_content' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Do not add srcset and sizes while testing.
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3014,7 +3019,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 50756
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_wp_filter_content_tags_loading_lazy_opted_out() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $img    = get_image_tag( self::$large_id, '', '', '', 'medium' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $img    = wp_img_tag_add_decoding_attr( get_image_tag( self::$large_id, '', '', '', 'medium' ), 'the_content' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $iframe = '<iframe src="https://www.example.com" width="640" height="360"></iframe>';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $content = '
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3478,7 +3483,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Following the threshold of 2, the first two content media elements should not be lazy-loaded.
</span><span class="cx" style="display: block; padding: 0 10px">                $content_unfiltered = $img1 . $iframe1 . $img2 . $img3 . $iframe2;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $content_expected   = $img1 . $iframe1 . $lazy_img2 . $lazy_img3 . $lazy_iframe2;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $content_expected   = wp_img_tag_add_decoding_attr( $img1 . $iframe1 . $lazy_img2 . $lazy_img3 . $lazy_iframe2, 'the_content' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $wp_query     = new WP_Query( array( 'post__in' => array( self::$post_ids['publish'] ) ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $wp_the_query = $wp_query;
</span></span></pre>
</div>
</div>

</body>
</html>