Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix post featured image scaling on the front #46838

Merged
merged 7 commits into from
Jan 13, 2023
15 changes: 10 additions & 5 deletions packages/block-library/src/post-featured-image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,27 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
if ( $is_link ) {
$link_target = $attributes['linkTarget'];
$rel = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
$height = ! empty( $attributes['height'] ) ? 'style="' . esc_attr( safecss_filter_attr( 'height:' . esc_attr( $attributes['height'] ) ) ) . '"' : '';
carolinan marked this conversation as resolved.
Show resolved Hide resolved
$featured_image = sprintf(
'<a href="%1$s" target="%2$s" %3$s>%4$s%5$s</a>',
'<a href="%1$s" target="%2$s" %3$s %4$s>%5$s%6$s</a>',
get_the_permalink( $post_ID ),
esc_attr( $link_target ),
$rel,
$height,
$featured_image,
$overlay_markup
);
} else {
$featured_image = $featured_image . $overlay_markup;
}

$wrapper_attributes = empty( $attributes['width'] )
? get_block_wrapper_attributes()
: get_block_wrapper_attributes( array( 'style' => "width:{$attributes['width']};" ) );

$width = ! empty( $attributes['width'] ) ? esc_attr( safecss_filter_attr( 'width:' . esc_attr( $attributes['width'] ) ) ) . ';' : '';
$height = ! empty( $attributes['height'] ) ? esc_attr( safecss_filter_attr( 'height:' . esc_attr( $attributes['height'] ) ) ) . ';' : '';
if ( ! $height && ! $width ) {
$wrapper_attributes = get_block_wrapper_attributes();
} else {
$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $width . $height ) );
carolinan marked this conversation as resolved.
Show resolved Hide resolved
}
return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

Expand Down