Make WordPress Core

Changeset 35402


Ignore:
Timestamp:
10/26/2015 04:28:27 PM (9 years ago)
Author:
SergeyBiryukov
Message:

Remove assignments from conditions in wp_get_attachment_image() and wp_img_add_srcset_and_sizes().

See #34379.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r35401 r35402  
    810810            $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
    811811
    812         $attr = wp_parse_args($attr, $default_attr);
     812        $attr   = wp_parse_args( $attr, $default_attr );
     813        $srcset = wp_get_attachment_image_srcset( $attachment_id, $size );
     814        $sizes  = wp_get_attachment_image_sizes( $attachment_id, $size, $width );
    813815
    814816        // Generate srcset and sizes if not already present.
    815         if ( empty( $attr['srcset'] ) && ( $srcset = wp_get_attachment_image_srcset( $attachment_id, $size ) ) && ( $sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width ) ) ) {
     817        if ( empty( $attr['srcset'] ) && $srcset && $sizes ) {
    816818            $attr['srcset'] = $srcset;
    817819
     
    11491151    }
    11501152
     1153    $meta = wp_get_attachment_metadata( $id );
     1154
    11511155    /*
    11521156     * If attempts to parse the size value failed, attempt to use the image
    11531157     * metadata to match the 'src' against the available sizes for an attachment.
    11541158     */
    1155     if ( ! $size && ! empty( $id ) && is_array( $meta = wp_get_attachment_metadata( $id ) ) ) {
     1159    if ( ! $size && ! empty( $id ) && is_array( $meta ) ) {
    11561160        // Parse the image src value from the img element.
    11571161        $src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : false;
     
    11811185    }
    11821186
     1187    $srcset = wp_get_attachment_image_srcset( $id, $size );
     1188    $sizes  = wp_get_attachment_image_sizes( $id, $size, $width );
     1189
    11831190    // If ID and size exist, try for 'srcset' and 'sizes' and update the markup.
    1184     if ( $id && $size && ( $srcset = wp_get_attachment_image_srcset( $id, $size ) ) && ( $sizes = wp_get_attachment_image_sizes( $id, $size, $width ) ) ) {
     1191    if ( $id && $size && $srcset && $sizes ) {
    11851192        // Format the srcset and sizes string and escape attributes.
    11861193        $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes) );
Note: See TracChangeset for help on using the changeset viewer.