Make WordPress Core


Ignore:
Timestamp:
07/21/2020 11:12:22 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Widgets: Make sure image widgets with custom image size render captions.

Props kasparsd, JavierCasares, audrasjb.
Fixes #50160.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-media-image.php

    r47055 r48557  
    185185
    186186        $attachment = null;
     187
    187188        if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) {
    188189            $attachment = get_post( $instance['attachment_id'] );
    189190        }
     191
    190192        if ( $attachment ) {
    191193            $caption = '';
     
    209211
    210212            $size = $instance['size'];
     213
    211214            if ( 'custom' === $size || ! in_array( $size, array_merge( get_intermediate_image_sizes(), array( 'full' ) ), true ) ) {
    212                 $size = array( $instance['width'], $instance['height'] );
    213             }
     215                $size  = array( $instance['width'], $instance['height'] );
     216                $width = $instance['width'];
     217            } else {
     218                $caption_size = _wp_get_image_size_from_meta( $instance['size'], wp_get_attachment_metadata( $attachment->ID ) );
     219                $width        = empty( $caption_size[0] ) ? 0 : $caption_size[0];
     220            }
     221
    214222            $image_attributes['class'] .= sprintf( ' attachment-%1$s size-%1$s', is_array( $size ) ? join( 'x', $size ) : $size );
    215223
    216224            $image = wp_get_attachment_image( $attachment->ID, $size, false, $image_attributes );
    217 
    218             $caption_size = _wp_get_image_size_from_meta( $instance['size'], wp_get_attachment_metadata( $attachment->ID ) );
    219             $width        = empty( $caption_size[0] ) ? 0 : $caption_size[0];
    220225
    221226        } else {
Note: See TracChangeset for help on using the changeset viewer.