<!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>[34855] trunk: Merge the Responsive Images feature plugin into core, initial commit.</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/34855">34855</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/34855","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>wonderboymusic</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-10-06 04:58:21 +0000 (Tue, 06 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'>Merge the Responsive Images feature plugin into core, initial commit. See: https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images/
New functions in `media.php`:
* `wp_get_attachment_image_srcset_array()` - Returns an array of image candidate string data used to build a `srcset` value for an attachment given an `$attachement_id` and `$size`.
* `wp_get_attachment_image_srcset()` - Returns the `srcset` value for an attachment given an `$attachement_id` and `$size`.
* `wp_get_attachment_image_sizes()` - Returns the `sizes` value for an attachment given an `$attachement_id` and `$size` and optional arguments used to alter its output.
* `wp_make_content_images_responsive()` - A display filter for adding `srcset` and `sizes` to images embedded in content.
* `wp_img_add_srcset_and_sizes()` - A utility function used by `wp_make_content_images_responsive()` to add `srcset` and `sizes` to a single `<img>` element.
Modifies existing core functions:
* Modify `wp_get_attachment_image()` so the HTML returned for an image includes `srcset` and `sizes`.
* Modify `get_media_embedded_in_content()` (sup, 3.6 leftover) by adding `<img>` to the list of accepted tags that can be matched in content. This is used in `wp_make_content_images_responsive()` to find all of the images embedded in content before passing them off to `wp_img_add_srcset_and_sizes()`.
Tests:
* Add a new factory method to `WP_UnitTest_Factory_For_Attachment` named `create_upload_object()`
* Adds unit tests
* Updates unit tests
Props joemcgill, tevko, jaspermdegroot, mdmcginn, barryceelen, peterwilsoncc, fsylum, wonderboymusic, chriscoyier, benjaminpick, jrfnl, <a href="https://core.trac.wordpress.org/ticket/12">#12</a>kingkool68, janhenckens, ryanmarkel, side777, ryelle, wturrell, micahmills, mattbagwell, coliff, DrewAPicture.
See <a href="https://core.trac.wordpress.org/ticket/33641">#33641</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesdefaultfiltersphp">trunk/src/wp-includes/default-filters.php</a></li>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
<li><a href="#trunktestsphpunitincludesfactoryphp">trunk/tests/phpunit/includes/factory.php</a></li>
<li><a href="#trunktestsphpunittestsmediaphp">trunk/tests/phpunit/tests/media.php</a></li>
<li><a href="#trunktestsphpunittestspostthumbnailsphp">trunk/tests/phpunit/tests/post/thumbnails.php</a></li>
<li><a href="#trunktestsphpunittestsxmlrpcmweditPostphp">trunk/tests/phpunit/tests/xmlrpc/mw/editPost.php</a></li>
<li><a href="#trunktestsphpunittestsxmlrpcmwgetPostphp">trunk/tests/phpunit/tests/xmlrpc/mw/getPost.php</a></li>
<li><a href="#trunktestsphpunittestsxmlrpcmwgetRecentPostsphp">trunk/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php</a></li>
<li><a href="#trunktestsphpunittestsxmlrpcmwnewPostphp">trunk/tests/phpunit/tests/xmlrpc/mw/newPost.php</a></li>
<li><a href="#trunktestsphpunittestsxmlrpcwpeditPostphp">trunk/tests/phpunit/tests/xmlrpc/wp/editPost.php</a></li>
<li><a href="#trunktestsphpunittestsxmlrpcwpnewPostphp">trunk/tests/phpunit/tests/xmlrpc/wp/newPost.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunitdataimagestestimagelargepng">trunk/tests/phpunit/data/images/test-image-large.png</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesdefaultfiltersphp"></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/default-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/default-filters.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/src/wp-includes/default-filters.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -129,12 +129,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'the_title', 'convert_chars' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'the_title', 'trim' );
</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_filter( 'the_content', 'wptexturize' );
-add_filter( 'the_content', 'convert_smilies' );
-add_filter( 'the_content', 'convert_chars' );
-add_filter( 'the_content', 'wpautop' );
-add_filter( 'the_content', 'shortcode_unautop' );
-add_filter( 'the_content', 'prepend_attachment' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'the_content', 'wptexturize' );
+add_filter( 'the_content', 'convert_smilies' );
+add_filter( 'the_content', 'convert_chars' );
+add_filter( 'the_content', 'wpautop' );
+add_filter( 'the_content', 'shortcode_unautop' );
+add_filter( 'the_content', 'prepend_attachment' );
+add_filter( 'the_content', 'wp_make_content_images_responsive' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'the_excerpt', 'wptexturize' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'the_excerpt', 'convert_smilies' );
</span></span></pre></div>
<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-06 04:34:03 UTC (rev 34854)
+++ trunk/src/wp-includes/media.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -777,6 +777,16 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Generate srcset and sizes if not already present.
+ if ( empty( $attr['srcset'] ) && $srcset = wp_get_attachment_image_srcset( $attachment_id, $size ) ) {
+ $attr['srcset'] = $srcset;
+ $sizes_args = array(
+ 'height' => $height,
+ 'width' => $width,
+ );
+ $attr['sizes'] = wp_get_attachment_image_sizes( $attachment_id, $size, $sizes_args );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filter the list of attachment image attributes.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -815,6 +825,382 @@
</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">+ * Retrieves an array of URLs and pixel widths representing sizes of an image.
+ *
+ * The purpose is to populate a source set when creating responsive image markup.
+ *
+ * @since 4.4.0
+ *
+ * @param int $attachment_id Image attachment ID.
+ * @param string $size Optional. Name of image size. Default 'medium'.
+ * @return array|bool $images {
+ * Array image candidate values containing a URL, descriptor type, and
+ * descriptor value. False if none exist.
+ *
+ * @type array $values {
+ * @type string $url An image URL.
+ * @type string $descriptor A width or density descriptor used in a srcset.
+ * @type int $value The descriptor value representing a width or
+ * or pixel density.
+ * }
+ * }
+ *
+ */
+function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' ) {
+ // Get the intermediate size.
+ $image = image_get_intermediate_size( $attachment_id, $size );
+
+ // Get the post meta.
+ $img_meta = wp_get_attachment_metadata( $attachment_id );
+ if ( ! is_array( $img_meta ) ) {
+ return false;
+ }
+
+ // Extract the height and width from the intermediate or the full size.
+ $img_width = ( $image ) ? $image['width'] : $img_meta['width'];
+ $img_height = ( $image ) ? $image['height'] : $img_meta['height'];
+
+ // Bail early if the width isn't greater that zero.
+ if ( ! $img_width > 0 ) {
+ return false;
+ }
+
+ // Use the URL from the intermediate size or build the url from the metadata.
+ if ( ! empty( $image['url'] ) ) {
+ $img_url = $image['url'];
+ } else {
+ $uploads_dir = wp_upload_dir();
+ $img_file = ( $image ) ? path_join( dirname( $img_meta['file'] ) , $image['file'] ) : $img_meta['file'];
+ $img_url = $uploads_dir['baseurl'] . '/' . $img_file;
+ }
+
+ $img_sizes = $img_meta['sizes'];
+
+ // Add full size to the img_sizes array.
+ $img_sizes['full'] = array(
+ 'width' => $img_meta['width'],
+ 'height' => $img_meta['height'],
+ 'file' => wp_basename( $img_meta['file'] )
+ );
+
+ // Calculate the image aspect ratio.
+ $img_ratio = $img_height / $img_width;
+
+ /*
+ * Images that have been edited in WordPress after being uploaded will
+ * contain a unique hash. Look for that hash and use it later to filter
+ * out images that are leftovers from previous versions.
+ */
+ $img_edited = preg_match( '/-e[0-9]{13}/', $img_url, $img_edit_hash );
+
+ /*
+ * Set up arrays to hold url candidates and matched image sources so
+ * we can avoid duplicates without looping through the full sources array
+ */
+ $candidates = $sources = array();
+
+ /*
+ * Loop through available images and only use images that are resized
+ * versions of the same rendition.
+ */
+ foreach ( $img_sizes as $img ) {
+
+ // Filter out images that are leftovers from previous renditions.
+ if ( $img_edited && ! strpos( $img['file'], $img_edit_hash[0] ) ) {
+ continue;
+ }
+
+ $candidate_url = path_join( dirname( $img_url ), $img['file'] );
+
+ // Calculate the new image ratio.
+ $img_ratio_compare = $img['height'] / $img['width'];
+
+ // If the new ratio differs by less than 0.01, use it.
+ if ( abs( $img_ratio - $img_ratio_compare ) < 0.01 && ! in_array( $candidate_url, $candidates ) ) {
+ // Add the URL to our list of candidates.
+ $candidates[] = $candidate_url;
+
+ // Add the url, descriptor, and value to the sources array to be returned.
+ $sources[] = array(
+ 'url' => $candidate_url,
+ 'descriptor' => 'w',
+ 'value' => $img['width'],
+ );
+ }
+ }
+
+ /**
+ * Filter the output of wp_get_attachment_image_srcset_array().
+ *
+ * @since 4.4.0
+ *
+ * @param array $sources An array of image urls and widths.
+ * @param int $attachment_id Attachment ID for image.
+ * @param array|string $size Size of image, either array or string.
+ */
+ return apply_filters( 'wp_get_attachment_image_srcset_array', $sources, $attachment_id, $size );
+}
+
+/**
+ * Retrieves the value for an image attachment's 'srcset' attribute.
+ *
+ * @since 4.4.0
+ *
+ * @param int $attachment_id Image attachment ID.
+ * @param string $size Optional. Name of image size. Default 'medium'.
+ * @return string|bool A 'srcset' value string or false.
+ */
+function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium' ) {
+ $srcset_array = wp_get_attachment_image_srcset_array( $attachment_id, $size );
+
+ // Only return a srcset value if there is more than one source.
+ if ( count( $srcset_array ) <= 1 ) {
+ return false;
+ }
+
+ $srcset = '';
+ foreach ( $srcset_array as $source ) {
+ $srcset .= $source['url'] . ' ' . $source['value'] . $source['descriptor'] . ', ';
+ }
+
+ /**
+ * Filter the output of wp_get_attachment_image_srcset().
+ *
+ * @since 4.4.0
+ *
+ * @param string $srcset A source set formated for a `srcset` attribute.
+ * @param int $attachment_id Attachment ID for image.
+ * @param array|string $size Size of image, either array or string.
+ */
+ return apply_filters( 'wp_get_attachment_image_srcset', rtrim( $srcset, ', ' ), $attachment_id, $size );
+}
+
+/**
+ * Retrieves a source size attribute for an image from an array of values.
+ *
+ * @since 4.4.0
+ *
+ * @param int $attachment_id Image attachment ID.
+ * @param string $size Optional. Name of image size. Default value: 'medium'.
+ * @param array $args {
+ * Optional. Arguments to retrieve attachments.
+ *
+ * @type array|string $sizes An array or string containing of size information.
+ * @type int $width A single width value used in the default `sizes` string.
+ * }
+ * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
+ */
+function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $args = null ) {
+
+ // Try to get the image width from $args before calling image_downsize().
+ if ( is_array( $args ) && ! empty( $args['width'] ) ) {
+ $img_width = (int) $args['width'];
+ } elseif ( $img = image_get_intermediate_size( $attachment_id, $size ) ) {
+ list( $img_width, $img_height ) = image_constrain_size_for_editor( $img['width'], $img['height'], $size );
+ }
+
+ // Bail early if $image_width isn't set.
+ if ( ! $img_width ) {
+ return false;
+ }
+
+ // Set the image width in pixels.
+ $img_width = $img_width . 'px';
+
+ // Set up our default values.
+ $defaults = array(
+ 'sizes' => array(
+ array(
+ 'size_value' => '100vw',
+ 'mq_value' => $img_width,
+ 'mq_name' => 'max-width'
+ ),
+ array(
+ 'size_value' => $img_width
+ ),
+ )
+ );
+
+ $args = wp_parse_args( $args, $defaults );
+
+ /**
+ * Filter arguments used to create 'sizes' attribute.
+ *
+ * @since 4.4.0
+ *
+ * @param array $args An array of arguments used to create a 'sizes' attribute.
+ * @param int $attachment_id Post ID of the original image.
+ * @param string $size Name of the image size being used.
+ */
+ $args = apply_filters( 'wp_image_sizes_args', $args, $attachment_id, $size );
+
+ // If sizes is passed as a string, just use the string.
+ if ( is_string( $args['sizes'] ) ) {
+ $size_list = $args['sizes'];
+
+ // Otherwise, breakdown the array and build a sizes string.
+ } elseif ( is_array( $args['sizes'] ) ) {
+
+ $size_list = '';
+
+ foreach ( $args['sizes'] as $size ) {
+
+ // Use 100vw as the size value unless something else is specified.
+ $size_value = ( $size['size_value'] ) ? $size['size_value'] : '100vw';
+
+ // If a media length is specified, build the media query.
+ if ( ! empty( $size['mq_value'] ) ) {
+
+ $media_length = $size['mq_value'];
+
+ // Use max-width as the media condition unless min-width is specified.
+ $media_condition = ( ! empty( $size['mq_name'] ) ) ? $size['mq_name'] : 'max-width';
+
+ // If a media_length was set, create the media query.
+ $media_query = '(' . $media_condition . ": " . $media_length . ') ';
+
+ } else {
+ // If no media length was set, $media_query is blank.
+ $media_query = '';
+ }
+
+ // Add to the source size list string.
+ $size_list .= $media_query . $size_value . ', ';
+ }
+
+ // Remove the trailing comma and space from the end of the string.
+ $size_list = substr( $size_list, 0, -2 );
+ }
+
+ // Return the sizes value as $size_list or false.
+ return ( $size_list ) ? $size_list : false;
+}
+
+/**
+ * Filters 'img' elements in post content to add 'srcset' and 'sizes' attributes.
+ *
+ * @since 4.4.0
+ *
+ * @see wp_img_add_srcset_and_sizes()
+ *
+ * @param string $content The raw post content to be filtered.
+ * @return string Converted content with 'srcset' and 'sizes' attributes added to images.
+ */
+function wp_make_content_images_responsive( $content ) {
+ $images = get_media_embedded_in_content( $content, 'img' );
+
+ $attachment_ids = array();
+
+ foreach( $images as $image ) {
+ if ( preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) ) {
+ $attachment_id = (int) $class_id[1];
+ if ( $attachment_id ) {
+ $attachment_ids[] = $attachment_id;
+ }
+ }
+ }
+
+ if ( 0 < count( $attachment_ids ) ) {
+ /*
+ * Warm object caches for use with wp_get_attachment_metadata.
+ *
+ * To avoid making a database call for each image, a single query
+ * warms the object cache with the meta information for all images.
+ */
+ _prime_post_caches( $attachment_ids, false, true );
+ }
+
+ foreach( $images as $image ) {
+ $content = str_replace( $image, wp_img_add_srcset_and_sizes( $image ), $content );
+ }
+
+ return $content;
+}
+
+/**
+ * Adds 'srcset' and 'sizes' attributes to an existing 'img' element.
+ *
+ * @since 4.4.0
+ *
+ * @see wp_get_attachment_image_srcset()
+ * @see wp_get_attachment_image_sizes()
+ *
+ * @param string $image An HTML 'img' element to be filtered.
+ * @return string Converted 'img' element with `srcset` and `sizes` attributes added.
+ */
+function wp_img_add_srcset_and_sizes( $image ) {
+ // Return early if a 'srcset' attribute already exists.
+ if ( false !== strpos( $image, ' srcset="' ) ) {
+ return $image;
+ }
+
+ // Parse id, size, width, and height from the `img` element.
+ $id = preg_match( '/wp-image-([0-9]+)/i', $image, $match_id ) ? (int) $match_id[1] : false;
+ $size = preg_match( '/size-([^\s|"]+)/i', $image, $match_size ) ? $match_size[1] : false;
+ $width = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1] : false;
+ $height = preg_match( '/ height="([0-9]+)"/', $image, $match_height ) ? (int) $match_height[1] : false;
+
+ if ( $id && false === $size ) {
+ $size = array( $width, $height );
+ }
+
+ /*
+ * If attempts to parse the size value failed, attempt to use the image
+ * metadata to match the 'src' against the available sizes for an attachment.
+ */
+ if ( ! $size && ! empty( $id ) && is_array( $meta = wp_get_attachment_metadata( $id ) ) ) {
+ // Parse the image src value from the img element.
+ $src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : false;
+
+ // Return early if the src value is empty.
+ if ( ! $src ) {
+ return $image;
+ }
+
+ /*
+ * First, see if the file is the full size image. If not, loop through
+ * the intermediate sizes until we find a file that matches.
+ */
+ $image_filename = wp_basename( $src );
+
+ if ( $image_filename === basename( $meta['file'] ) ) {
+ $size = 'full';
+ } else {
+ foreach( $meta['sizes'] as $image_size => $image_size_data ) {
+ if ( $image_filename === $image_size_data['file'] ) {
+ $size = $image_size;
+ break;
+ }
+ }
+ }
+
+ }
+
+ // If ID and size, try for 'srcset' and 'sizes' and update the markup.
+ if ( $id && $size && $srcset = wp_get_attachment_image_srcset( $id, $size ) ) {
+
+ /*
+ * Pass the 'height' and 'width' to 'wp_get_attachment_image_sizes()' to avoid
+ * recalculating the image size.
+ */
+ $args = array(
+ 'height' => $height,
+ 'width' => $width,
+ );
+
+ $sizes = wp_get_attachment_image_sizes( $id, $size, $args );
+
+ // Format the srcset and sizes string and escape attributes.
+ $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes) );
+
+ // Add srcset and sizes attributes to the image markup.
+ $image = preg_replace( '/<img ([^>]+)[\s?][\/?]>/', '<img $1' . $srcset_and_sizes . ' />', $image );
+ }
+
+ return $image;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Adds a 'wp-post-image' class to post thumbnails. Internal use only.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Uses the 'begin_fetch_post_thumbnail_html' and 'end_fetch_post_thumbnail_html' action hooks to
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2986,11 +3372,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Filter the embedded media types that are allowed to be returned from the content blob.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.4.0 Added 'img' to the allowed types.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $allowed_media_types An array of allowed media types. Default media types are
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 'audio', 'video', 'object', 'embed', and 'iframe'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * 'audio', 'video', 'object', 'embed', 'iframe', and 'img'.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe', 'img' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $types ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_array( $types ) ) {
</span></span></pre></div>
<a id="trunktestsphpunitdataimagestestimagelargepng"></a>
<div class="binary"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/images/test-image-large.png</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx" style="display: block; padding: 0 10px">Index: trunk/tests/phpunit/data/images/test-image-large.png
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- trunk/tests/phpunit/data/images/test-image-large.png 2015-10-06 04:34:03 UTC (rev 34854)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ trunk/tests/phpunit/data/images/test-image-large.png 2015-10-06 04:58:21 UTC (rev 34855)
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/images/test-image-large.png
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:mime-type</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+application/octet-stream
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitincludesfactoryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/includes/factory.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -94,6 +94,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function create_object( $file, $parent = 0, $args = array() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_insert_attachment( $args, $file, $parent );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ function create_upload_object( $file, $parent = 0 ) {
+ $contents = file_get_contents($file);
+ $upload = wp_upload_bits(basename($file), null, $contents);
+
+ $type = '';
+ if ( ! empty($upload['type']) ) {
+ $type = $upload['type'];
+ } else {
+ $mime = wp_check_filetype( $upload['file'] );
+ if ($mime)
+ $type = $mime['type'];
+ }
+
+ $attachment = array(
+ 'post_title' => basename( $upload['file'] ),
+ 'post_content' => '',
+ 'post_type' => 'attachment',
+ 'post_parent' => $parent,
+ 'post_mime_type' => $type,
+ 'guid' => $upload[ 'url' ],
+ );
+
+ // Save the data
+ $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent );
+ wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
+
+ return $id;
+ }
</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"> class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing {
</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 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/tests/media.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,7 +18,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->img_name = 'image.jpg';
</span><span class="cx" style="display: block; padding: 0 10px"> $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->img_html = '<img src="' . $this->img_url . '"/>';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->img_dimensions = array( 'width' => 100, 'height' => 100 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->img_meta = array( 'width' => 100, 'height' => 100, '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"> function test_img_caption_shortcode_added() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -288,7 +288,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_mime_type' => 'image/jpeg',
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => 'attachment'
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_update_attachment_metadata( $attachment_id, $this->img_dimensions );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta );
+ wp_update_attachment_metadata( $attachment_id, $metadata );
</ins><span class="cx" style="display: block; padding: 0 10px"> $ids1[] = $attachment_id;
</span><span class="cx" style="display: block; padding: 0 10px"> $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -300,7 +301,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_mime_type' => 'image/jpeg',
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => 'attachment'
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_update_attachment_metadata( $attachment_id, $this->img_dimensions );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta );
+ wp_update_attachment_metadata( $attachment_id, $metadata );
</ins><span class="cx" style="display: block; padding: 0 10px"> $ids2[] = $attachment_id;
</span><span class="cx" style="display: block; padding: 0 10px"> $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -329,7 +331,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_mime_type' => 'image/jpeg',
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => 'attachment'
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_update_attachment_metadata( $attachment_id, $this->img_dimensions );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta );
+ wp_update_attachment_metadata( $attachment_id, $metadata );
</ins><span class="cx" style="display: block; padding: 0 10px"> $ids1[] = $attachment_id;
</span><span class="cx" style="display: block; padding: 0 10px"> $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -341,7 +344,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_mime_type' => 'image/jpeg',
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => 'attachment'
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_update_attachment_metadata( $attachment_id, $this->img_dimensions );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta );
+ wp_update_attachment_metadata( $attachment_id, $metadata );
</ins><span class="cx" style="display: block; padding: 0 10px"> $ids2[] = $attachment_id;
</span><span class="cx" style="display: block; padding: 0 10px"> $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -501,6 +505,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'test-size', $_wp_additional_image_sizes );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 200, $_wp_additional_image_sizes['test-size']['width'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 600, $_wp_additional_image_sizes['test-size']['height'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Clean up
</ins><span class="cx" style="display: block; padding: 0 10px"> remove_image_size( 'test-size' );
</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">@@ -520,6 +526,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function test_has_image_size() {
</span><span class="cx" style="display: block; padding: 0 10px"> add_image_size( 'test-size', 200, 600 );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( has_image_size( 'test-size' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Clean up
</ins><span class="cx" style="display: block; padding: 0 10px"> remove_image_size( 'test-size' );
</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">@@ -737,4 +745,356 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $image[0], wp_get_attachment_image_url( $attachment_id ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_srcset_array() {
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+
+ $year_month = date('Y/m');
+ $image = wp_get_attachment_metadata( $id );
+
+ $expected = array(
+ array(
+ 'url' => 'http://example.org/wp-content/uploads/' . $year_month . '/' . $image['sizes']['medium']['file'],
+ 'descriptor' => 'w',
+ 'value' => $image['sizes']['medium']['width'],
+ ),
+ array(
+ 'url' => 'http://example.org/wp-content/uploads/' . $year_month . '/' . $image['sizes']['large']['file'],
+ 'descriptor' => 'w',
+ 'value' => $image['sizes']['large']['width'],
+ ),
+ array(
+ 'url' => 'http://example.org/wp-content/uploads/' . $image['file'],
+ 'descriptor' => 'w',
+ 'value' => $image['width'],
+ ),
+ );
+
+ // Set up test cases for all expected size names and a random one.
+ $sizes = array( 'medium', 'large', 'full', 'yoav' );
+
+ foreach ( $sizes as $size ) {
+ $this->assertSame( $expected, wp_get_attachment_image_srcset_array( $id, $size ) );
+ }
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_srcset_array_no_date_upoads() {
+ // Save the current setting for uploads folders
+ $uploads_use_yearmonth_folders = get_option( 'uploads_use_yearmonth_folders' );
+
+ // Disable date organized uploads
+ update_option( 'uploads_use_yearmonth_folders', 0 );
+
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+
+ $image = wp_get_attachment_metadata( $id );
+
+ $expected = array(
+ array(
+ 'url' => 'http://example.org/wp-content/uploads/' . $image['sizes']['medium']['file'],
+ 'descriptor' => 'w',
+ 'value' => $image['sizes']['medium']['width'],
+ ),
+ array(
+ 'url' => 'http://example.org/wp-content/uploads/' . $image['sizes']['large']['file'],
+ 'descriptor' => 'w',
+ 'value' => $image['sizes']['large']['width'],
+ ),
+ array(
+ 'url' => 'http://example.org/wp-content/uploads/' . $image['file'],
+ 'descriptor' => 'w',
+ 'value' => $image['width'],
+ ),
+ );
+
+ // Set up test cases for all expected size names and a random one.
+ $sizes = array( 'medium', 'large', 'full', 'yoav' );
+
+ foreach ( $sizes as $size ) {
+ $this->assertSame( $expected, wp_get_attachment_image_srcset_array( $id, $size ) );
+ }
+
+ // Leave the uploads option the way you found it.
+ update_option( 'uploads_use_yearmonth_folders', $uploads_use_yearmonth_folders );
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_srcset_array_with_edits() {
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+ // For this test we're going to mock metadata changes from an edit.
+ // Start by getting the attachment metadata.
+ $meta = wp_get_attachment_metadata( $id );
+
+ // Copy hash generation method used in wp_save_image().
+ $hash = 'e' . time() . rand(100, 999);
+
+ // Replace file paths for full and medium sizes with hashed versions.
+ $filename_base = basename( $meta['file'], '.png' );
+ $meta['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $meta['file'] );
+ $meta['sizes']['medium']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $meta['sizes']['medium']['file'] );
+
+ // Save edited metadata.
+ wp_update_attachment_metadata( $id, $meta );
+
+ // Get the edited image and observe that a hash was created.
+ $img_url = wp_get_attachment_url( $id );
+
+ // Calculate a srcset array.
+ $sizes = wp_get_attachment_image_srcset_array( $id, 'medium' );
+
+ // Test to confirm all sources in the array include the same edit hash.
+ foreach ( $sizes as $size ) {
+ $this->assertTrue( false !== strpos( $size['url'], $hash ) );
+ }
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_srcset_array_false() {
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+ $sizes = wp_get_attachment_image_srcset_array( 99999, 'foo' );
+
+ // For canola.jpg we should return
+ $this->assertFalse( $sizes );
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_srcset_array_no_width() {
+ // Filter image_downsize() output.
+ add_filter( 'wp_generate_attachment_metadata', array( $this, '_test_wp_get_attachment_image_srcset_array_no_width_filter' ) );
+
+ // Make our attachment.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+ $srcset = wp_get_attachment_image_srcset_array( $id, 'medium' );
+
+ // The srcset should be false.
+ $this->assertFalse( $srcset );
+
+ // Remove filter.
+ remove_filter( 'wp_generate_attachment_metadata', array( $this, '_test_wp_get_attachment_image_srcset_array_no_width_filter' ) );
+ }
+
+ /**
+ * Helper function to filter image_downsize and return zero values for width and height.
+ */
+ public function _test_wp_get_attachment_image_srcset_array_no_width_filter( $meta ) {
+ $meta['sizes']['medium']['width'] = 0;
+ $meta['sizes']['medium']['height'] = 0;
+ return $meta;
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_srcset() {
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+ $sizes = wp_get_attachment_image_srcset( $id, 'full-size' );
+
+ $image = wp_get_attachment_metadata( $id );
+ $year_month = date('Y/m');
+
+ $expected = 'http://example.org/wp-content/uploads/' . $year_month = date('Y/m') . '/'
+ . $image['sizes']['medium']['file'] . ' ' . $image['sizes']['medium']['width'] . 'w, ';
+ $expected .= 'http://example.org/wp-content/uploads/' . $year_month = date('Y/m') . '/'
+ . $image['sizes']['large']['file'] . ' ' . $image['sizes']['large']['width'] . 'w, ';
+ $expected .= 'http://example.org/wp-content/uploads/' . $image['file'] . ' ' . $image['width'] .'w';
+
+ $this->assertSame( $expected, $sizes );
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_srcset_single_srcset() {
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+ /*
+ * In our tests, thumbnails will only return a single srcset candidate,
+ * so we shouldn't return a srcset value in order to avoid unneeded markup.
+ */
+ $sizes = wp_get_attachment_image_srcset( $id, 'thumbnail' );
+
+ $this->assertFalse( $sizes );
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_sizes() {
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+
+
+ global $content_width;
+
+ // Test sizes against the default WP sizes.
+ $intermediates = array('thumbnail', 'medium', 'large');
+
+ foreach( $intermediates as $int ) {
+ $width = get_option( $int . '_size_w' );
+
+ // The sizes width gets constrained to $content_width by default.
+ if ( $content_width > 0 ) {
+ $width = ( $width > $content_width ) ? $content_width : $width;
+ }
+
+ $expected = '(max-width: ' . $width . 'px) 100vw, ' . $width . 'px';
+ $sizes = wp_get_attachment_image_sizes( $id, $int );
+
+ $this->assertSame($expected, $sizes);
+ }
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_sizes_with_args() {
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+
+
+ $args = array(
+ 'sizes' => array(
+ array(
+ 'size_value' => '10em',
+ 'mq_value' => '60em',
+ 'mq_name' => 'min-width'
+ ),
+ array(
+ 'size_value' => '20em',
+ 'mq_value' => '30em',
+ 'mq_name' => 'min-width'
+ ),
+ array(
+ 'size_value' => 'calc(100vm - 30px)'
+ ),
+ )
+ );
+
+ $expected = '(min-width: 60em) 10em, (min-width: 30em) 20em, calc(100vm - 30px)';
+ $sizes = wp_get_attachment_image_sizes( $id, 'medium', $args );
+
+ $this->assertSame($expected, $sizes);
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_get_attachment_image_sizes_with_filtered_args() {
+ // Add our test filter.
+ add_filter( 'wp_image_sizes_args', array( $this, '_test_wp_image_sizes_args' ) );
+
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+
+ $sizes = wp_get_attachment_image_sizes($id, 'medium');
+
+ // Evaluate that the sizes returned is what we expected.
+ $this->assertSame( $sizes, '100vm');
+
+ remove_filter( 'wp_image_sizes_args', array( $this, '_test_wp_image_sizes_args' ) );
+ }
+
+ /**
+ * A simple test filter for wp_get_attachment_image_sizes().
+ */
+ function _test_wp_image_sizes_args( $args ) {
+ $args['sizes'] = "100vm";
+ return $args;
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_make_content_images_responsive() {
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+
+ $srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( $id, 'medium' ) );
+ $sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( $id, 'medium' ) );
+
+ // Function used to build HTML for the editor.
+ $img = get_image_tag( $id, '', '', '', 'medium' );
+ $img_no_size = str_replace( 'size-', '', $img );
+ $img_no_size_id = str_replace( 'wp-image-', 'id-', $img_no_size );
+
+ // Manually add srcset and sizes to the markup from get_image_tag();
+ $respimg = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img);
+ $respimg_no_size = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size);
+
+ $content = '<p>Welcome to WordPress! This post contains important information. After you read it, you can make it private to hide it from visitors but still have the information handy for future reference.</p>
+ <p>First things first:</p>
+
+ %1$s
+
+ <ul>
+ <li><a href="http://wordpress.org" title="Subscribe to the WordPress mailing list for Release Notifications">Subscribe to the WordPress mailing list for release notifications</a></li>
+ </ul>
+
+ %2$s
+
+ <p>As a subscriber, you will receive an email every time an update is available (and only then). This will make it easier to keep your site up to date, and secure from evildoers.<br />
+ When a new version is released, <a href="http://wordpress.org" title="If you are already logged in, this will take you directly to the Dashboard">log in to the Dashboard</a> and follow the instructions.<br />
+ Upgrading is a couple of clicks!</p>
+
+ %3$s
+
+ <p>Then you can start enjoying the WordPress experience:</p>
+ <ul>
+ <li>Edit your personal information at <a href="http://wordpress.org" title="Edit settings like your password, your display name and your contact information">Users › Your Profile</a></li>
+ <li>Start publishing at <a href="http://wordpress.org" title="Create a new post">Posts › Add New</a> and at <a href="http://wordpress.org" title="Create a new page">Pages › Add New</a></li>
+ <li>Browse and install plugins at <a href="http://wordpress.org" title="Browse and install plugins at the official WordPress repository directly from your Dashboard">Plugins › Add New</a></li>
+ <li>Browse and install themes at <a href="http://wordpress.org" title="Browse and install themes at the official WordPress repository directly from your Dashboard">Appearance › Add New Themes</a></li>
+ <li>Modify and prettify your website’s links at <a href="http://wordpress.org" title="For example, select a link structure like: http://example.com/1999/12/post-name">Settings › Permalinks</a></li>
+ <li>Import content from another system or WordPress site at <a href="http://wordpress.org" title="WordPress comes with importers for the most common publishing systems">Tools › Import</a></li>
+ <li>Find answers to your questions at the <a href="http://wordpress.orgs" title="The official WordPress documentation, maintained by the WordPress community">WordPress Codex</a></li>
+ </ul>';
+
+ $content_unfiltered = sprintf( $content, $img, $img_no_size, $img_no_size_id );
+ $content_filtered = sprintf( $content, $respimg, $respimg_no_size, $img_no_size_id );
+
+ $this->assertSame( $content_filtered, wp_make_content_images_responsive( $content_unfiltered ) );
+ }
+
+ /**
+ * @ticket 33641
+ */
+ function test_wp_make_content_images_responsive_with_preexisting_srcset() {
+ // Make an image.
+ $filename = DIR_TESTDATA . '/images/test-image-large.png';
+ $id = $this->factory->attachment->create_upload_object( $filename );
+
+ // Generate HTML and add a dummy srcset attribute.
+ $image_html = get_image_tag( $id, '', '', '', 'medium' );
+ $image_html = preg_replace('|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $image_html );
+
+ // The content filter should return the image unchanged.
+ $this->assertSame( $image_html, wp_make_content_images_responsive( $image_html ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestspostthumbnailsphp"></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/post/thumbnails.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/thumbnails.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/tests/post/thumbnails.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -13,7 +13,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->post = $this->factory->post->create_and_get();
</span><span class="cx" style="display: block; padding: 0 10px"> $file = DIR_TESTDATA . '/images/canola.jpg';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->attachment_id = $this->factory->attachment->create_object( $file, $this->post->ID, array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->attachment_id = $this->factory->attachment->create_upload_object( $file, $this->post->ID, array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'post_mime_type' => 'image/jpeg',
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsxmlrpcmweditPostphp"></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/xmlrpc/mw/editPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/xmlrpc/mw/editPost.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/tests/xmlrpc/mw/editPost.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,18 +126,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // create attachment
</span><span class="cx" style="display: block; padding: 0 10px"> $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $contents = file_get_contents( $filename );
- $upload = wp_upload_bits( $filename, null, $contents );
- $this->assertTrue( empty( $upload['error'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $attachment_id = $this->factory->attachment->create_upload_object( $filename, $post_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">- $attachment = array(
- 'post_title' => 'Post Thumbnail',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image/jpeg',
- 'guid' => $upload['url']
- );
- $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // add post thumbnail to post that does not have one
</span><span class="cx" style="display: block; padding: 0 10px"> $post2 = array( 'wp_post_thumbnail' => $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post2 ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -151,8 +141,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // create another attachment
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $attachment2 = array_merge( $attachment, array( 'title' => 'Post Thumbnail 2' ) );
- $attachment2_id = wp_insert_attachment( $attachment2, $upload['file'], $post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $attachment2_id = $this->factory->attachment->create_upload_object( $filename, $post_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // change the post's post_thumbnail
</span><span class="cx" style="display: block; padding: 0 10px"> $post4 = array( 'wp_post_thumbnail' => $attachment2_id );
</span></span></pre></div>
<a id="trunktestsphpunittestsxmlrpcmwgetPostphp"></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/xmlrpc/mw/getPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/xmlrpc/mw/getPost.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/tests/xmlrpc/mw/getPost.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,18 +95,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // create attachment
</span><span class="cx" style="display: block; padding: 0 10px"> $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $contents = file_get_contents( $filename );
- $upload = wp_upload_bits( $filename, null, $contents );
- $this->assertTrue( empty( $upload['error'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $attachment_id = $this->factory->attachment->create_upload_object( $filename );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $attachment = array(
- 'post_title' => 'Post Thumbnail',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image/jpeg',
- 'guid' => $upload['url']
- );
- $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $this->post_id );
-
</del><span class="cx" style="display: block; padding: 0 10px"> set_post_thumbnail( $this->post_id, $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $fields = array( 'post' );
</span></span></pre></div>
<a id="trunktestsphpunittestsxmlrpcmwgetRecentPostsphp"></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/xmlrpc/mw/getRecentPosts.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -39,7 +39,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertInstanceOf( 'IXR_Error', $result );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 401, $result->code );
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> function test_no_editable_posts() {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_delete_post( $this->post_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -100,17 +100,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // create attachment
</span><span class="cx" style="display: block; padding: 0 10px"> $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $contents = file_get_contents( $filename );
- $upload = wp_upload_bits( $filename, null, $contents );
- $this->assertTrue( empty( $upload['error'] ) );
-
- $attachment = array(
- 'post_title' => 'Post Thumbnail',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image/jpeg',
- 'guid' => $upload['url']
- );
- $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $this->post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $attachment_id = $this->factory->attachment->create_upload_object( $filename, $this->post_id );
</ins><span class="cx" style="display: block; padding: 0 10px"> set_post_thumbnail( $this->post_id, $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $results = $this->myxmlrpcserver->mw_getRecentPosts( array( $this->post_id, 'author', 'author' ) );
</span></span></pre></div>
<a id="trunktestsphpunittestsxmlrpcmwnewPostphp"></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/xmlrpc/mw/newPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/xmlrpc/mw/newPost.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/tests/xmlrpc/mw/newPost.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -117,18 +117,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // create attachment
</span><span class="cx" style="display: block; padding: 0 10px"> $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $contents = file_get_contents( $filename );
- $upload = wp_upload_bits( $filename, null, $contents );
- $this->assertTrue( empty( $upload['error'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $attachment_id = $this->factory->attachment->create_upload_object( $filename );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $attachment = array(
- 'post_title' => 'Post Thumbnail',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image/jpeg',
- 'guid' => $upload['url']
- );
- $attachment_id = wp_insert_attachment( $attachment, $upload['file'] );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $post = array( 'title' => 'Post Thumbnail Test', 'wp_post_thumbnail' => $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertNotInstanceOf( 'IXR_Error', $result );
</span></span></pre></div>
<a id="trunktestsphpunittestsxmlrpcwpeditPostphp"></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/xmlrpc/wp/editPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/xmlrpc/wp/editPost.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/tests/xmlrpc/wp/editPost.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -113,7 +113,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $out = get_post( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $editor_id, $out->post_author );
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> function test_post_thumbnail() {
</span><span class="cx" style="display: block; padding: 0 10px"> add_theme_support( 'post-thumbnails' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,18 +126,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // create attachment
</span><span class="cx" style="display: block; padding: 0 10px"> $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $contents = file_get_contents( $filename );
- $upload = wp_upload_bits( $filename, null, $contents );
- $this->assertTrue( empty( $upload['error'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $attachment_id = $this->factory->attachment->create_upload_object( $filename, $post_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">- $attachment = array(
- 'post_title' => 'Post Thumbnail',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image/jpeg',
- 'guid' => $upload['url']
- );
- $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // add post thumbnail to post that does not have one
</span><span class="cx" style="display: block; padding: 0 10px"> $post2 = array( 'post_thumbnail' => $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post2 ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -158,8 +148,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // create another attachment
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $attachment2 = array_merge( $attachment, array( 'post_title' => 'Post Thumbnail 2' ) );
- $attachment2_id = wp_insert_attachment( $attachment2, $upload['file'], $post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $attachment2_id = $this->factory->attachment->create_upload_object( $filename, $post_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // change the post's post_thumbnail
</span><span class="cx" style="display: block; padding: 0 10px"> $post4 = array( 'post_thumbnail' => $attachment2_id );
</span></span></pre></div>
<a id="trunktestsphpunittestsxmlrpcwpnewPostphp"></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/xmlrpc/wp/newPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/xmlrpc/wp/newPost.php 2015-10-06 04:34:03 UTC (rev 34854)
+++ trunk/tests/phpunit/tests/xmlrpc/wp/newPost.php 2015-10-06 04:58:21 UTC (rev 34855)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -128,18 +128,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // create attachment
</span><span class="cx" style="display: block; padding: 0 10px"> $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $contents = file_get_contents( $filename );
- $upload = wp_upload_bits( $filename, null, $contents );
- $this->assertTrue( empty( $upload['error'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $attachment_id = $this->factory->attachment->create_upload_object( $filename );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $attachment = array(
- 'post_title' => 'Post Thumbnail',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image/jpeg',
- 'guid' => $upload['url']
- );
- $attachment_id = wp_insert_attachment( $attachment, $upload['file'] );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $post = array( 'post_title' => 'Post Thumbnail Test', 'post_thumbnail' => $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertNotInstanceOf( 'IXR_Error', $result );
</span></span></pre>
</div>
</div>
</body>
</html>