Make WordPress Core

Ticket #34430: 34430.10.diff

File 34430.10.diff, 3.0 KB (added by jaspermdegroot, 9 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 79fb36e..bba996f 100644
    function _wp_get_image_size_from_meta( $size_name, $image_meta ) { 
    930930 *
    931931 * @since 4.4.0
    932932 *
    933  * @param int          $attachment_id Optional. Image attachment ID.
     933 * @param int          $attachment_id Image attachment ID.
    934934 * @param array|string $size          Image size. Accepts any valid image size, or an array of width and height
    935935 *                                    values in pixels (in that order). Default 'medium'.
    936936 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
    function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $imag 
    941941                return false;
    942942        }
    943943
    944         if ( ! is_array( $image_meta ) ) {
    945                 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
    946         }
    947 
    948944        $image_url = $image[0];
    949945        $size_array = array(
    950946                absint( $image[1] ),
    951947                absint( $image[2] )
    952948        );
    953949
     950        if ( empty( $image_meta['sizes'] ) ) {
     951                $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
     952
     953                if ( ! is_array( $image_meta ) ) {
     954                        return false;
     955                }
     956        }
     957
    954958        return wp_calculate_image_srcset( $image_url, $size_array, $image_meta, $attachment_id );
    955959}
    956960
    function wp_calculate_image_srcset( $image_name, $size_array, $image_meta, $atta 
    10591063         *
    10601064         * @since 4.4.0
    10611065         *
    1062          * @param array $sources       An array of image URLs and widths.
     1066         * @param array $sources       An array of sources to include in the 'srcset'. Each source
     1067         *                             consists of an array containing the URL and the descriptor
     1068         *                             type and value (default: the image width):
     1069         *
     1070         *                             image width => array(
     1071         *                                 'url'        => string,
     1072         *                                 'descriptor' => string ('w' or 'x'),
     1073         *                                 'value'      => integer (width or pixel density)
     1074         *                             },
     1075         *
    10631076         * @param int   $attachment_id Image attachment ID.
    10641077         * @param array $size_array    Array of width and height values in pixels (in that order).
    10651078         * @param array $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
    function wp_calculate_image_srcset( $image_name, $size_array, $image_meta, $atta 
    10981111function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0, $image_url = null ) {
    10991112        $width = 0;
    11001113
    1101         if ( is_numeric( $size ) ) {
    1102                 $width = absint( $size );
    1103         } elseif ( is_array( $size ) ) {
     1114        if ( is_array( $size ) ) {
    11041115                $width = absint( $size[0] );
    11051116        } elseif ( is_string( $size ) ) {
    11061117                if ( ! $image_meta && $attachment_id ) {
    1107                         $image_meta = wp_get_attachment_metadata( $attachment_id );
     1118                        $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
    11081119                }
    11091120
    11101121                if ( is_array( $image_meta ) ) {