mirror of
https://github.com/WordPress/WordPress.git
synced 2024-06-28 07:45:02 +02:00
Widgets: Make sure image widgets with custom image size render captions.
Props kasparsd, JavierCasares, audrasjb. Fixes #50160. Built from https://develop.svn.wordpress.org/trunk@48557 git-svn-id: http://core.svn.wordpress.org/trunk@48319 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5323fa05e5
commit
19779e6302
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.5-beta3-48556';
|
$wp_version = '5.5-beta3-48557';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
|
@ -184,9 +184,11 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
|
||||||
);
|
);
|
||||||
|
|
||||||
$attachment = null;
|
$attachment = null;
|
||||||
|
|
||||||
if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) {
|
if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) {
|
||||||
$attachment = get_post( $instance['attachment_id'] );
|
$attachment = get_post( $instance['attachment_id'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $attachment ) {
|
if ( $attachment ) {
|
||||||
$caption = '';
|
$caption = '';
|
||||||
if ( ! isset( $instance['caption'] ) ) {
|
if ( ! isset( $instance['caption'] ) ) {
|
||||||
|
@ -208,16 +210,19 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
|
||||||
}
|
}
|
||||||
|
|
||||||
$size = $instance['size'];
|
$size = $instance['size'];
|
||||||
|
|
||||||
if ( 'custom' === $size || ! in_array( $size, array_merge( get_intermediate_image_sizes(), array( 'full' ) ), true ) ) {
|
if ( 'custom' === $size || ! in_array( $size, array_merge( get_intermediate_image_sizes(), array( 'full' ) ), true ) ) {
|
||||||
$size = array( $instance['width'], $instance['height'] );
|
$size = array( $instance['width'], $instance['height'] );
|
||||||
|
$width = $instance['width'];
|
||||||
|
} else {
|
||||||
|
$caption_size = _wp_get_image_size_from_meta( $instance['size'], wp_get_attachment_metadata( $attachment->ID ) );
|
||||||
|
$width = empty( $caption_size[0] ) ? 0 : $caption_size[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$image_attributes['class'] .= sprintf( ' attachment-%1$s size-%1$s', is_array( $size ) ? join( 'x', $size ) : $size );
|
$image_attributes['class'] .= sprintf( ' attachment-%1$s size-%1$s', is_array( $size ) ? join( 'x', $size ) : $size );
|
||||||
|
|
||||||
$image = wp_get_attachment_image( $attachment->ID, $size, false, $image_attributes );
|
$image = wp_get_attachment_image( $attachment->ID, $size, false, $image_attributes );
|
||||||
|
|
||||||
$caption_size = _wp_get_image_size_from_meta( $instance['size'], wp_get_attachment_metadata( $attachment->ID ) );
|
|
||||||
$width = empty( $caption_size[0] ) ? 0 : $caption_size[0];
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ( empty( $instance['url'] ) ) {
|
if ( empty( $instance['url'] ) ) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user