Media: don't use `get_media_embedded_in_content()` in `wp_make_content_images_responsive()`.

Adds unit test.

Props azaozz.
Fixes #34807.

Built from https://develop.svn.wordpress.org/trunk@35753


git-svn-id: http://core.svn.wordpress.org/trunk@35717 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-12-01 20:50:25 +00:00
parent d569b9609e
commit eaae2546f5
2 changed files with 7 additions and 6 deletions

View File

@ -1206,11 +1206,13 @@ function wp_calculate_image_sizes( $size, $image_src = null, $image_meta = null,
* @return string Converted content with 'srcset' and 'sizes' attributes added to images. * @return string Converted content with 'srcset' and 'sizes' attributes added to images.
*/ */
function wp_make_content_images_responsive( $content ) { function wp_make_content_images_responsive( $content ) {
$images = get_media_embedded_in_content( $content, 'img' ); if ( ! preg_match_all( '/<img [^>]+>/', $content, $matches ) ) {
return $content;
}
$selected_images = $attachment_ids = array(); $selected_images = $attachment_ids = array();
foreach( $images as $image ) { foreach( $matches[0] as $image ) {
if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) &&
( $attachment_id = absint( $class_id[1] ) ) ) { ( $attachment_id = absint( $class_id[1] ) ) ) {
@ -3506,12 +3508,11 @@ function get_media_embedded_in_content( $content, $types = null ) {
* Filter the embedded media types that are allowed to be returned from the content blob. * Filter the embedded media types that are allowed to be returned from the content blob.
* *
* @since 4.2.0 * @since 4.2.0
* @since 4.4.0 Added 'img' to the allowed types.
* *
* @param array $allowed_media_types An array of allowed media types. Default media types are * @param array $allowed_media_types An array of allowed media types. Default media types are
* 'audio', 'video', 'object', 'embed', 'iframe', and 'img'. * 'audio', 'video', 'object', 'embed', and 'iframe'.
*/ */
$allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe', 'img' ) ); $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) );
if ( ! empty( $types ) ) { if ( ! empty( $types ) ) {
if ( ! is_array( $types ) ) { if ( ! is_array( $types ) ) {

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-RC1-35752'; $wp_version = '4.4-RC1-35753';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.