Make WordPress Core

Ticket #34898: 34898.diff

File 34898.diff, 1.0 KB (added by kovshenin, 9 years ago)
  • src/wp-includes/media.php

     
    12781278                return $image;
    12791279        }
    12801280
     1281        $base_url = trailingslashit( _wp_upload_dir_baseurl() );
     1282        $image_base_url = $base_url;
     1283
     1284        $dirname = dirname( $image_meta['file'] );
     1285        if ( $dirname !== '.' ) {
     1286                $image_base_url .= trailingslashit( $dirname );
     1287        }
     1288
     1289        $all_sizes = wp_list_pluck( $image_meta['sizes'], 'file' );
     1290
     1291        foreach ( $all_sizes as $key => $file ) {
     1292                $all_sizes[ $key ] = $image_base_url . $file;
     1293        }
     1294
     1295        // Add the original image.
     1296        $all_sizes[] = $base_url . $image_meta['file'];
     1297
     1298        // Bail early if the image src doesn't match any of the known image sizes.
     1299        if ( ! in_array( $image_src, $all_sizes ) ) {
     1300                return $image;
     1301        }
     1302
    12811303        $width  = preg_match( '/ width="([0-9]+)"/',  $image, $match_width  ) ? (int) $match_width[1]  : 0;
    12821304        $height = preg_match( '/ height="([0-9]+)"/', $image, $match_height ) ? (int) $match_height[1] : 0;
    12831305