diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/widgets/class-wp-widget-media-image.php --- a/wp/wp-includes/widgets/class-wp-widget-media-image.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/widgets/class-wp-widget-media-image.php Tue Dec 15 13:49:49 2020 +0100 @@ -12,6 +12,7 @@ * * @since 4.8.0 * + * @see WP_Widget_Media * @see WP_Widget */ class WP_Widget_Media_Image extends WP_Widget_Media { @@ -39,11 +40,11 @@ 'replace_media' => _x( 'Replace Image', 'label for button in the image widget; should preferably not be longer than ~13 characters long' ), 'edit_media' => _x( 'Edit Image', 'label for button in the image widget; should preferably not be longer than ~13 characters long' ), 'missing_attachment' => sprintf( - /* translators: %s: URL to media library */ + /* translators: %s: URL to media library. */ __( 'We can’t find that image. Check your media library and make sure it wasn’t deleted.' ), esc_url( admin_url( 'upload.php' ) ) ), - /* translators: %d: widget count */ + /* translators: %d: Widget count. */ 'media_library_state_multi' => _n_noop( 'Image Widget (%d)', 'Image Widget (%d)' ), 'media_library_state_single' => __( 'Image Widget' ), ) @@ -58,6 +59,7 @@ * @see WP_REST_Controller::get_item_schema() * @see WP_REST_Controller::get_additional_fields() * @link https://core.trac.wordpress.org/ticket/35574 + * * @return array Schema for properties. */ public function get_instance_schema() { @@ -171,7 +173,6 @@ * @since 4.8.0 * * @param array $instance Widget instance props. - * @return void */ public function render_media( $instance ) { $instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance ); @@ -183,9 +184,11 @@ ); $attachment = null; + if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) { $attachment = get_post( $instance['attachment_id'] ); } + if ( $attachment ) { $caption = ''; if ( ! isset( $instance['caption'] ) ) { @@ -207,16 +210,19 @@ } $size = $instance['size']; + 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 = 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 { if ( empty( $instance['url'] ) ) { return; @@ -334,7 +340,7 @@ <# if ( data.url ) { #>
<# } #> @@ -354,7 +360,7 @@