Ticket #34807: 34807.2.patch
File 34807.2.patch, 4.1 KB (added by , 8 years ago) |
---|
-
src/wp-includes/media.php
1206 1206 * @return string Converted content with 'srcset' and 'sizes' attributes added to images. 1207 1207 */ 1208 1208 function wp_make_content_images_responsive( $content ) { 1209 $images = get_media_embedded_in_content( $content, 'img' ); 1209 if ( ! preg_match_all( '/<img [^>]+>/', $content, $matches ) ) { 1210 return $content; 1211 } 1210 1212 1211 1213 $selected_images = $attachment_ids = array(); 1212 1214 1213 foreach( $ imagesas $image ) {1215 foreach( $matches[0] as $image ) { 1214 1216 if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && 1215 1217 ( $attachment_id = absint( $class_id[1] ) ) ) { 1216 1218 … … 3506 3508 * Filter the embedded media types that are allowed to be returned from the content blob. 3507 3509 * 3508 3510 * @since 4.2.0 3509 * @since 4.4.0 Added 'img' to the allowed types.3510 3511 * 3511 3512 * @param array $allowed_media_types An array of allowed media types. Default media types are 3512 * 'audio', 'video', 'object', 'embed', 'iframe', and 'img'.3513 * 'audio', 'video', 'object', 'embed', and 'iframe'. 3513 3514 */ 3514 $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' , 'img') );3515 $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) ); 3515 3516 3516 3517 if ( ! empty( $types ) ) { 3517 3518 if ( ! is_array( $types ) ) { -
tests/phpunit/tests/media.php
962 962 $img_no_width_height = str_replace( ' height="' . $size_array[1] . '"', '', $img_no_width_height ); 963 963 $img_no_size_id = str_replace( 'wp-image-', 'id-', $img ); 964 964 $img_with_sizes_attr = str_replace( '<img ', '<img sizes="99vw" ', $img ); 965 $img_xhtml = str_replace( ' />', '/>', $img ); 966 $img_html5 = str_replace( ' />', '>', $img ); 965 967 966 968 // Manually add srcset and sizes to the markup from get_image_tag(); 967 969 $respimg = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img ); … … 968 970 $respimg_no_size_in_class = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size_in_class ); 969 971 $respimg_no_width_height = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height ); 970 972 $respimg_with_sizes_attr = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr ); 973 $respimg_xhtml = preg_replace( '|<img ([^>]+)/>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_xhtml ); 974 $respimg_html5 = preg_replace( '|<img ([^>]+)>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_html5 ); 971 975 972 976 $content = ' 973 977 <p>Image, standard. Should have srcset and sizes.</p> … … 983 987 %4$s 984 988 985 989 <p>Image, with sizes attribute. Should NOT have two sizes attributes.</p> 986 %5$s ';990 %5$s 987 991 988 $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 );992 <p>Image, XHTML 1.0 style (no space before the closing slash). Should have srcset and sizes.</p> 993 %6$s 990 994 995 <p>Image, HTML 5.0 style. Should have srcset and sizes.</p> 996 %7$s'; 997 998 $content_unfiltered = sprintf( $content, $img, $img_no_size_in_class, $img_no_width_height, $img_no_size_id, $img_with_sizes_attr, $img_xhtml, $img_html5 ); 999 $content_filtered = sprintf( $content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $respimg_with_sizes_attr, $respimg_xhtml, $respimg_html5 ); 1000 991 1001 $this->assertSame( $content_filtered, wp_make_content_images_responsive( $content_unfiltered ) ); 992 1002 } 993 1003