<!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>[35419] trunk/src/wp-includes/media.php: Responsive images:</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 { 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/35419">35419</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/35419","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-10-28 20:00:14 +0000 (Wed, 28 Oct 2015)</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'>Responsive images:
- Check if wp_get_attachment_metadata() has returned an array to prevent errors when using SVGs.
- Only add the srcset attribute if there will be a sizes attribute.
- Better filter names.
- Some more inline docs fixes.

Props jaspermdegroot.
See <a href="https://core.trac.wordpress.org/ticket/34430">#34430</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/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   2015-10-28 18:18:42 UTC (rev 35418)
+++ trunk/src/wp-includes/media.php     2015-10-28 20:00:14 UTC (rev 35419)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -811,17 +811,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $attr = wp_parse_args( $attr, $default_attr );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Generate srcset and sizes if not already present.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Generate 'srcset' and 'sizes' if not already present.
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( empty( $attr['srcset'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $image_meta = wp_get_attachment_metadata( $attachment_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $size_array = array( absint( $width ), absint( $height ) );
-                       $sources = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( count( $sources ) > 1 ) {
-                               $attr['srcset'] = wp_image_srcset_attr( $sources, $size_array, $image_meta, $attachment_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( is_array( $image_meta ) ) {
+                               $size_array = array( absint( $width ), absint( $height ) );
+                               $sources    = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id );
+                               $sizes      = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( empty( $attr['sizes'] ) && ( $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id ) ) ) {
-                                       $attr['sizes'] = $sizes;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( count( $sources ) > 1 && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
+                                       $attr['srcset'] = wp_image_srcset_attr( $sources, $size_array, $image_meta, $attachment_id );
+
+                                       if ( empty( $attr['sizes'] ) ) {
+                                               $attr['sizes'] = $sizes;
+                                       }
</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">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -906,7 +910,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @param int          $attachment_id Optional. Image attachment ID.
</span><span class="cx" style="display: block; padding: 0 10px">  * @param array|string $size          Image size. Accepts any valid image size, or an array of width and height
</span><span class="cx" style="display: block; padding: 0 10px">  *                                    values in pixels (in that order). Default 'medium'.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array        $image_meta    Optional. The image meta data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @return string|bool A 'srcset' value string or false.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -924,10 +928,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                absint( $image[2] )
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Calculate the sources for the srcset.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Calculate the sources for the 'srcset'.
</ins><span class="cx" style="display: block; padding: 0 10px">         $sources = wp_calculate_image_srcset( $image_url, $size_array, $image_meta, $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Only return a srcset value if there is more than one source.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Only return a 'srcset' value if there is more than one source.
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( count( $sources ) < 2 ) {
</span><span class="cx" style="display: block; padding: 0 10px">                return false;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -937,15 +941,15 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * A helper function to concatenate and filter the srcset attribute value.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * A helper function to concatenate and filter the 'srcset' attribute value.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array   $sources       The array containing image sizes data as returned by wp_calculate_image_srcset().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array   $sources       The array containing image sizes data as returned by 'wp_calculate_image_srcset()'.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @param array   $size_array    Array of width and height values in pixels (in that order).
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array   $image_meta    The image meta data.
- * @param int     $attachment_id The image attachment post id to pass to the filter.
- * @return string The srcset attribute value.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array   $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
+ * @param int     $attachment_id The image attachment ID to pass to the filter.
+ * @return string The 'srcset' attribute value.
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_image_srcset_attr( $sources, $size_array, $image_meta, $attachment_id ) {
</span><span class="cx" style="display: block; padding: 0 10px">        $srcset = '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -955,40 +959,39 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Filter the output of wp_get_attachment_image_srcset().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Filter the output of 'wp_image_srcset_attr()'.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param string       $srcset        A source set formatted for a `srcset` attribute.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param string       $srcset        A source set formatted for a 'srcset' attribute.
</ins><span class="cx" style="display: block; padding: 0 10px">          * @param int          $attachment_id Image attachment ID.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param array|string $size          Image size. Accepts any valid image size, or an array of width and height
-        *                                    values in pixels (in that order). Default 'medium'.
-        * @param array        $image_meta    The image meta data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param array|string $size          Image size. Image size name, or an array of width and height
+        *                                    values in pixels (in that order).
+        * @param array        $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        return apply_filters( 'wp_get_attachment_image_srcset', rtrim( $srcset, ', ' ), $attachment_id, $size_array, $image_meta );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'wp_image_srcset', rtrim( $srcset, ', ' ), $attachment_id, $size_array, $image_meta );
</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"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * A helper function to caclulate the image sources to include in a srcset attribute.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * A helper function to calculate the image sources to include in a 'srcset' attribute.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $image_name    The file name, path, URL or partial path or URL of the image being matched.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $image_name    The file name, path, URL, or partial path or URL, of the image being matched.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @param array  $size_array    Array of width and height values in pixels (in that order).
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array  $image_meta    The image meta data.
- * @param int    $attachment_id Optional. The image attachment post id to pass to the filter.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
+ * @param int    $attachment_id Optional. The image attachment ID to pass to the filter.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @return array|bool $sources {
</span><span class="cx" style="display: block; padding: 0 10px">  *     Array image candidate values containing a URL, descriptor type, and
</span><span class="cx" style="display: block; padding: 0 10px">  *     descriptor value. False if none exist.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  *     @type array $values {
</span><span class="cx" style="display: block; padding: 0 10px">  *        @type string $url        An image URL.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *        @type string $descriptor A width or density descriptor used in a srcset.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *        @type string $descriptor A width or density descriptor used in a 'srcset'.
</ins><span class="cx" style="display: block; padding: 0 10px">  *        @type int    $value      The descriptor value representing a width or
</span><span class="cx" style="display: block; padding: 0 10px">  *                                 or pixel density.
</span><span class="cx" style="display: block; padding: 0 10px">  *     }
</span><span class="cx" style="display: block; padding: 0 10px">  * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_calculate_image_srcset( $image_name, $size_array, $image_meta, $attachment_id = 0 ) {
</span><span class="cx" style="display: block; padding: 0 10px">        if ( empty( $image_meta['sizes'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -997,7 +1000,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        $image_sizes = $image_meta['sizes'];
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Get the height and width for the image.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Get the width and height of the image.
</ins><span class="cx" style="display: block; padding: 0 10px">         $image_width = (int) $size_array[0];
</span><span class="cx" style="display: block; padding: 0 10px">        $image_height = (int) $size_array[1];
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1006,7 +1009,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return false;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Add full size to the img_sizes array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Add full size to the '$img_sizes' array.
</ins><span class="cx" style="display: block; padding: 0 10px">         $image_sizes['full'] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                'width'  => $image_meta['width'],
</span><span class="cx" style="display: block; padding: 0 10px">                'height' => $image_meta['height'],
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1031,14 +1034,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">        $image_edited = preg_match( '/-e[0-9]{13}/', $image_name, $image_edit_hash );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Filter the maximum width included in a 'srcset' attribute.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Filter the maximum image width to be included in a 'srcset' attribute.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param int          $max_width  The maximum width to include in the 'srcset'. Default '1600'.
-        * @param array|string $size_array Array of width and height values in pixels (in that order).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param int   $max_width  The maximum image width to be included in the 'srcset'. Default '1600'.
+        * @param array $size_array Array of width and height values in pixels (in that order).
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $max_srcset_width = apply_filters( 'max_srcset_image_width', 1600, $size_array );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $max_srcset_image_width = apply_filters( 'max_srcset_image_width', 1600, $size_array );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Array to hold URL candidates.
</span><span class="cx" style="display: block; padding: 0 10px">        $sources = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1054,8 +1057,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        continue;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Filter out images that are wider than $max_srcset_width.
-               if ( $max_srcset_width && $image['width'] > $max_srcset_width ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Filter out images that are wider than '$max_srcset_image_width'.
+               if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         continue;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1080,30 +1083,30 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Filter the output of wp_get_attachment_image_srcset_array().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Filter the output of 'wp_calculate_image_srcset()'.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param array        $sources       An array of image URLs and widths.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param int          $attachment_id Attachment ID for image.
-        * @param array|string $size          Image size. Accepts any valid image size, or an array of width and height
-        *                                    values in pixels (in that order). Default 'medium'.
-        * @param array        $image_meta    The image meta data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param int          $attachment_id Image attachment ID.
+        * @param array|string $size          Image size. Image size name, or an array of width and height
+        *                                    values in pixels (in that order).
+        * @param array        $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        return apply_filters( 'wp_get_attachment_image_srcset_array', array_values( $sources ), $attachment_id, $size_array, $image_meta );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'wp_calculate_image_srcset', array_values( $sources ), $attachment_id, $size_array, $image_meta );
</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"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Create `sizes` attribute value for an image.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Create 'sizes' attribute value for an image.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array|string $size          Image size. Accepts any valid image size name (thumbnail, medium, etc.),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array|string $size          Image size. Accepts any valid image size name ('thumbnail', 'medium', etc.),
</ins><span class="cx" style="display: block; padding: 0 10px">  *                                    or an array of width and height values in pixels (in that order).
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array        $image_meta    Optional. The image meta data.
- * @param int          $attachment_id Optional. Image attachment ID. Either $image_meta or $attachment_id is needed
- *                                    when using image size name.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
+ * @param int          $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id` is needed
+ *                                    when using the image size name as argument for `$size`.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1119,10 +1122,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $image_meta = wp_get_attachment_metadata( $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $image_meta ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( is_array( $image_meta ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $width = _wp_get_image_size_from_meta( $size, $image_meta );
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( $width ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $width = $width[0];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $width = absint( $width[0] );
</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">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1131,19 +1134,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return false;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Setup the default sizes attribute.
-       $sizes = sprintf( '(max-width: %1$dpx) 100vw, %1$dpx', (int) $width );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Setup the default 'sizes' attribute.
+       $sizes = sprintf( '(max-width: %1$dpx) 100vw, %1$dpx', $width );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Filter the output of wp_get_attachment_image_sizes().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Filter the output of 'wp_get_attachment_image_sizes()'.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string       $sizes         A source size value for use in a 'sizes' attribute.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param array|string $size          Image size. Accepts any valid image size, or an array of width and height
-        *                                    values in pixels (in that order). Default 'medium'.
-        * @param array        $image_meta    The image meta data.
-        * @param int          $attachment_id Post ID of the original image.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param array|string $size          Image size. Image size name, or an array of width and height
+        *                                    values in pixels (in that order).
+        * @param array        $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
+        * @param int          $attachment_id Image attachment ID of the original image.
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1153,7 +1156,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see wp_image_add_srcset_and_sizes()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see 'wp_image_add_srcset_and_sizes()'
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $content The raw post content to be filtered.
</span><span class="cx" style="display: block; padding: 0 10px">  * @return string Converted content with 'srcset' and 'sizes' attributes added to images.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1167,8 +1170,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( false === strpos( $image, ' srcset="' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) &&
</span><span class="cx" style="display: block; padding: 0 10px">                        ( $attachment_id = absint( $class_id[1] ) ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // If exactly the same image tag is used more than once, overwrite it.
-                       // All identical tags will be replaced later with str_replace().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 /*
+                        * If exactly the same image tag is used more than once, overwrite it.
+                        * All identical tags will be replaced later with 'str_replace()'.
+                        */
</ins><span class="cx" style="display: block; padding: 0 10px">                         $selected_images[ $image ] = $attachment_id;
</span><span class="cx" style="display: block; padding: 0 10px">                        // Overwrite the ID when the same image is included more than once.
</span><span class="cx" style="display: block; padding: 0 10px">                        $attachment_ids[ $attachment_id ] = true;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1177,7 +1182,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( count( $attachment_ids ) > 1 ) {
</span><span class="cx" style="display: block; padding: 0 10px">                /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Warm object cache for use with get_post_meta().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Warm object cache for use with 'get_post_meta()'.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><span class="cx" style="display: block; padding: 0 10px">                 * To avoid making a database call for each image, a single query
</span><span class="cx" style="display: block; padding: 0 10px">                 * warms the object cache with the meta information for all images.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1198,16 +1203,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see wp_get_attachment_image_srcset()
- * @see wp_get_attachment_image_sizes()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see 'wp_get_attachment_image_srcset()'
+ * @see 'wp_get_attachment_image_sizes()'
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $image         An HTML 'img' element to be filtered.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array  $image_meta    The image meta data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @param int    $attachment_id Image attachment ID.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string Converted 'img' element with `srcset` and `sizes` attributes added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string Converted 'img' element with 'srcset' and 'sizes' attributes added.
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Ensure the image meta exists
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Ensure the image meta exists.
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( empty( $image_meta['sizes'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                return $image;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1215,12 +1220,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">        $src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';
</span><span class="cx" style="display: block; padding: 0 10px">        list( $src ) = explode( '?', $src );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Return early if we coudn't get the image source.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Return early if we couldn't get the image source.
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( ! $src ) {
</span><span class="cx" style="display: block; padding: 0 10px">                return $image;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Bail early when an image has been inserted and later edited.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Bail early if an image has been inserted and later edited.
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( preg_match( '/-e[0-9]{13}/', $image_meta['file'], $img_edit_hash ) &&
</span><span class="cx" style="display: block; padding: 0 10px">                strpos( wp_basename( $src ), $img_edit_hash[0] ) === false ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1232,8 +1237,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( ! $width || ! $height ) {
</span><span class="cx" style="display: block; padding: 0 10px">                /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * If attempts to parse the size value failed, attempt to use the image
-                * metadata to match the image file name from 'src' against the available sizes for an attachment.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * If attempts to parse the size value failed, attempt to use the image meta data to match
+                * the image file name from 'src' against the available sizes for an attachment.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><span class="cx" style="display: block; padding: 0 10px">                $image_filename = wp_basename( $src );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1259,17 +1264,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">        $sources = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        $srcset = $sizes = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Only calculate srcset and sizes values if there is more than one source.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Only calculate 'srcset' and 'sizes' values if there is more than one source.
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( count( $sources ) > 1 ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $srcset = wp_image_srcset_attr( $sources, $size_array, $image_meta, $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );
</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">        if ( $srcset && $sizes ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Format the srcset and sizes string and escape attributes.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Format the 'srcset' and 'sizes' string and escape attributes.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Add srcset and sizes attributes to the image markup.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Add 'srcset' and 'sizes' attributes to the image markup.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $image = preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $srcset_and_sizes . ' />', $image );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre>
</div>
</div>

</body>
</html>