Make WordPress Core

Ticket #34981: 34981.5.diff

File 34981.5.diff, 2.2 KB (added by desrosj, 4 years ago)
  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index 51c49f83d2..66ffa65e4b 100644
    a b function wp_prepare_attachment_for_js( $attachment ) { 
    42814281                 * to check the image metadata, which we do second.
    42824282                 */
    42834283                foreach ( $possible_sizes as $size => $label ) {
    4284 
    42854284                        /** This filter is documented in wp-includes/media.php */
    42864285                        $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size );
    42874286
    function wp_prepare_attachment_for_js( $attachment ) { 
    42964295                                        'url'         => $downsize[0],
    42974296                                        'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape',
    42984297                                );
    4299                         } elseif ( isset( $meta['sizes'][ $size ] ) ) {
    4300                                 // Nothing from the filter, so consult image metadata if we have it.
    4301                                 $size_meta = $meta['sizes'][ $size ];
    4302 
    4303                                 // We have the actual image size, but might need to further constrain it if content_width is narrower.
    4304                                 // Thumbnail, medium, and full sizes are also checked against the site's height/width options.
    4305                                 list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' );
     4298                        }
    43064299
    4307                                 $sizes[ $size ] = array(
    4308                                         'height'      => $height,
    4309                                         'width'       => $width,
    4310                                         'url'         => $base_url . $size_meta['file'],
    4311                                         'orientation' => $height > $width ? 'portrait' : 'landscape',
    4312                                 );
     4300                        // If the image_downsize filter did not return anything, use the metadata.
     4301                        if ( empty( $sizes ) && isset( $meta['sizes'] ) ) {
     4302                                foreach ( $meta['sizes'] as $size => $size_meta ) {
     4303                                        // We have the actual image size, but might need to further constrain it if content_width is narrower.
     4304                                        // Thumbnail, medium, and full sizes are also checked against the site's height/width options.
     4305                                        list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' );
     4306
     4307                                        $sizes[ $size ] = array(
     4308                                                        'height'      => $height,
     4309                                                        'width'       => $width,
     4310                                                        'url'         => $base_url . $size_meta['file'],
     4311                                                        'orientation' => $height > $width ? 'portrait' : 'landscape',
     4312                                        );
     4313                                }
    43134314                        }
    43144315                }
    43154316