Ticket #34678: 34678.2.diff
| File 34678.2.diff, 3.2 KB (added by , 11 years ago) |
|---|
-
src/wp-includes/media.php
1211 1211 $selected_images = $attachment_ids = array(); 1212 1212 1213 1213 foreach( $images as $image ) { 1214 if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id) &&1215 ( $attachment_id = absint( $class_id[1] ) ) ) {1214 if ( false === strpos( $image, ' srcset=' ) && false === strpos( $image, ' sizes=' ) && 1215 preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && ( $attachment_id = absint( $class_id[1] ) ) ) { 1216 1216 1217 1217 /* 1218 1218 * If exactly the same image tag is used more than once, overwrite it. … … 1308 1308 $srcset = wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id ); 1309 1309 1310 1310 if ( $srcset ) { 1311 // Check if there is already a 'sizes' attribute. 1312 $sizes = strpos( $image, ' sizes=' ); 1313 1314 if ( ! $sizes ) { 1315 $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id ); 1316 } 1311 $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id ); 1317 1312 } 1318 1313 1319 1314 if ( $srcset && $sizes ) { 1320 1315 // Format the 'srcset' and 'sizes' string and escape attributes. 1321 $attr = sprintf( ' srcset="%s" ', esc_attr( $srcset) );1316 $attr = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes ) ); 1322 1317 1323 if ( is_string( $sizes ) ) {1324 $attr .= sprintf( ' sizes="%s"', esc_attr( $sizes ) );1325 }1326 1327 1318 // Add 'srcset' and 'sizes' attributes to the image markup. 1328 1319 $image = preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $image ); 1329 1320 } -
tests/phpunit/tests/media.php
967 967 $respimg = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img ); 968 968 $respimg_no_size_in_class = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size_in_class ); 969 969 $respimg_no_width_height = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height ); 970 $respimg_with_sizes_attr = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr );971 970 972 971 $content = ' 973 972 <p>Image, standard. Should have srcset and sizes.</p> … … 982 981 <p>Image, no attachment ID class. Should NOT have srcset and sizes.</p> 983 982 %4$s 984 983 985 <p>Image, with sizes attribute. Should NOT have two sizes attributes.</p>984 <p>Image, with sizes attribute. Should NOT have srcset and sizes.</p> 986 985 %5$s'; 987 986 988 987 $content_unfiltered = sprintf( $content, $img, $img_no_size_in_class, $img_no_width_height, $img_no_size_id, $img_with_sizes_attr ); 989 $content_filtered = sprintf( $content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $ respimg_with_sizes_attr );988 $content_filtered = sprintf( $content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $img_with_sizes_attr ); 990 989 991 990 $this->assertSame( $content_filtered, wp_make_content_images_responsive( $content_unfiltered ) ); 992 991 }