From 4dcf28017c1ffd22757345707567d30c47e210dc Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Mon, 19 Sep 2022 21:37:48 +1000
Subject: [PATCH] Post Featured Image: Fix height/scale overwriting border
inline styles (#44213)
---
.../src/post-featured-image/index.php | 29 +++++++------------
1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/packages/block-library/src/post-featured-image/index.php b/packages/block-library/src/post-featured-image/index.php
index 931d87c0265c10..788917d3d252e5 100644
--- a/packages/block-library/src/post-featured-image/index.php
+++ b/packages/block-library/src/post-featured-image/index.php
@@ -29,11 +29,18 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
$attr['alt'] = $post_title;
}
+ if ( ! empty( $attributes['height'] ) ) {
+ $extra_styles = "height:{$attributes['height']};";
+ if ( ! empty( $attributes['scale'] ) ) {
+ $extra_styles .= "object-fit:{$attributes['scale']};";
+ }
+ $attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles;
+ }
+
$featured_image = get_the_post_thumbnail( $post_ID, $size_slug, $attr );
if ( ! $featured_image ) {
return '';
}
- $wrapper_attributes = get_block_wrapper_attributes();
if ( $is_link ) {
$link_target = $attributes['linkTarget'];
$rel = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
@@ -49,23 +56,9 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
$featured_image = $featured_image . $overlay_markup;
}
- $has_width = ! empty( $attributes['width'] );
- $has_height = ! empty( $attributes['height'] );
- if ( ! $has_height && ! $has_width ) {
- return "";
- }
-
- if ( $has_width ) {
- $wrapper_attributes = get_block_wrapper_attributes( array( 'style' => "width:{$attributes['width']};" ) );
- }
-
- if ( $has_height ) {
- $image_styles = "height:{$attributes['height']};";
- if ( ! empty( $attributes['scale'] ) ) {
- $image_styles .= "object-fit:{$attributes['scale']};";
- }
- $featured_image = str_replace( 'src=', 'style="' . esc_attr( $image_styles ) . '" src=', $featured_image );
- }
+ $wrapper_attributes = empty( $attributes['width'] )
+ ? get_block_wrapper_attributes()
+ : get_block_wrapper_attributes( array( 'style' => "width:{$attributes['width']};" ) );
return "";
}