Changeset 35753
- Timestamp:
- 12/01/2015 08:49:13 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r35725 r35753 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] ) ) ) { … … 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 */ 3514 $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' , 'img') );3513 * 'audio', 'video', 'object', 'embed', and 'iframe'. 3514 */ 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 ) ) { -
trunk/tests/phpunit/tests/media.php
r35751 r35753 1020 1020 $img_no_size_id = str_replace( 'wp-image-', 'id-', $img ); 1021 1021 $img_with_sizes_attr = str_replace( '<img ', '<img sizes="99vw" ', $img ); 1022 $img_xhtml = str_replace( ' />', '/>', $img ); 1023 $img_html5 = str_replace( ' />', '>', $img ); 1022 1024 1023 1025 // Manually add srcset and sizes to the markup from get_image_tag(); … … 1026 1028 $respimg_no_width_height = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height ); 1027 1029 $respimg_with_sizes_attr = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr ); 1030 $respimg_xhtml = preg_replace( '|<img ([^>]+)/>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_xhtml ); 1031 $respimg_html5 = preg_replace( '|<img ([^>]+)>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_html5 ); 1028 1032 1029 1033 $content = ' … … 1041 1045 1042 1046 <p>Image, with sizes attribute. Should NOT have two sizes attributes.</p> 1043 %5$s'; 1044 1045 $content_unfiltered = sprintf( $content, $img, $img_no_size_in_class, $img_no_width_height, $img_no_size_id, $img_with_sizes_attr ); 1046 $content_filtered = sprintf( $content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $respimg_with_sizes_attr ); 1047 %5$s 1048 1049 <p>Image, XHTML 1.0 style (no space before the closing slash). Should have srcset and sizes.</p> 1050 %6$s 1051 1052 <p>Image, HTML 5.0 style. Should have srcset and sizes.</p> 1053 %7$s'; 1054 1055 $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 ); 1056 $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 ); 1047 1057 1048 1058 $this->assertSame( $content_filtered, wp_make_content_images_responsive( $content_unfiltered ) );
Note: See TracChangeset
for help on using the changeset viewer.