WordPress.org

Make WordPress Core

Changeset 35404


Ignore:
Timestamp:
10/26/2015 06:40:01 PM (6 years ago)
Author:
SergeyBiryukov
Message:

After [35402], don't unnecessary run wp_get_attachment_image_srcset() and wp_get_attachment_image_sizes() in wp_get_attachment_image() if srcset is passed as an argument.

See #34379.

File:
1 edited

Legend:

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

    r35402 r35404  
    810810            $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
    811811
    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 );
     812        $attr = wp_parse_args( $attr, $default_attr );
    815813
    816814        // Generate srcset and sizes if not already present.
    817         if ( empty( $attr['srcset'] ) && $srcset && $sizes ) {
    818             $attr['srcset'] = $srcset;
    819 
    820             if ( empty( $attr['sizes'] ) ) {
    821                 $attr['sizes'] = $sizes;
     815        if ( empty( $attr['srcset'] ) ) {
     816            $srcset = wp_get_attachment_image_srcset( $attachment_id, $size );
     817            $sizes  = wp_get_attachment_image_sizes( $attachment_id, $size, $width );
     818
     819            if ( $srcset && $sizes ) {
     820                $attr['srcset'] = $srcset;
     821
     822                if ( empty( $attr['sizes'] ) ) {
     823                    $attr['sizes'] = $sizes;
     824                }
    822825            }
    823826        }
Note: See TracChangeset for help on using the changeset viewer.