Changeset 48557
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/widgets/class-wp-widget-media-image.php
r47055 r48557 185 185 186 186 $attachment = null; 187 187 188 if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) { 188 189 $attachment = get_post( $instance['attachment_id'] ); 189 190 } 191 190 192 if ( $attachment ) { 191 193 $caption = ''; … … 209 211 210 212 $size = $instance['size']; 213 211 214 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 214 222 $image_attributes['class'] .= sprintf( ' attachment-%1$s size-%1$s', is_array( $size ) ? join( 'x', $size ) : $size ); 215 223 216 224 $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];220 225 221 226 } else { -
trunk/tests/phpunit/tests/widgets/media-image-widget.php
r48464 r48557 586 586 $this->assertContains( 'class="wp-caption alignnone"', $output ); 587 587 $this->assertContains( '<p class="wp-caption-text">Custom caption</p>', $output ); 588 589 // Attachments with custom sizes can render captions. 590 ob_start(); 591 $widget->render_media( 592 array( 593 'attachment_id' => $attachment_id, 594 'size' => 'custom', 595 'width' => '300', 596 'height' => '200', 597 'caption' => 'Caption for an image with custom size', 598 ) 599 ); 600 $output = ob_get_clean(); 601 $this->assertContains( 'style="width: 310px"', $output ); 602 $this->assertContains( '<p class="wp-caption-text">Caption for an image with custom size</p>', $output ); 588 603 } 589 604
Note: See TracChangeset
for help on using the changeset viewer.