From f5d0260e4d071d2cadfd942067e96af48b211558 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 26 Oct 2015 16:29:26 +0000 Subject: [PATCH] Remove assignments from conditions in `wp_get_attachment_image()` and `wp_img_add_srcset_and_sizes()`. See #34379. Built from https://develop.svn.wordpress.org/trunk@35402 git-svn-id: http://core.svn.wordpress.org/trunk@35366 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 15 +++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 50d59a1de0..81eb18d42a 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -809,10 +809,12 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa if ( empty($default_attr['alt']) ) $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title - $attr = wp_parse_args($attr, $default_attr); + $attr = wp_parse_args( $attr, $default_attr ); + $srcset = wp_get_attachment_image_srcset( $attachment_id, $size ); + $sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width ); // Generate srcset and sizes if not already present. - if ( empty( $attr['srcset'] ) && ( $srcset = wp_get_attachment_image_srcset( $attachment_id, $size ) ) && ( $sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width ) ) ) { + if ( empty( $attr['srcset'] ) && $srcset && $sizes ) { $attr['srcset'] = $srcset; if ( empty( $attr['sizes'] ) ) { @@ -1148,11 +1150,13 @@ function wp_img_add_srcset_and_sizes( $image ) { } } + $meta = wp_get_attachment_metadata( $id ); + /* * 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 ) ) ) { + if ( ! $size && ! empty( $id ) && is_array( $meta ) ) { // Parse the image src value from the img element. $src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : false; @@ -1180,8 +1184,11 @@ function wp_img_add_srcset_and_sizes( $image ) { } + $srcset = wp_get_attachment_image_srcset( $id, $size ); + $sizes = wp_get_attachment_image_sizes( $id, $size, $width ); + // If ID and size exist, try for 'srcset' and 'sizes' and update the markup. - if ( $id && $size && ( $srcset = wp_get_attachment_image_srcset( $id, $size ) ) && ( $sizes = wp_get_attachment_image_sizes( $id, $size, $width ) ) ) { + if ( $id && $size && $srcset && $sizes ) { // Format the srcset and sizes string and escape attributes. $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 035670ff47..a0b28ac767 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-beta1-35401'; +$wp_version = '4.4-beta1-35402'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.