wp/wp-includes/blocks/post-featured-image.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-includes/blocks/post-featured-image.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/blocks/post-featured-image.php	Tue Sep 27 16:37:53 2022 +0200
@@ -19,18 +19,36 @@
 	}
 	$post_ID = $block->context['postId'];
 
-	$featured_image = get_the_post_thumbnail( $post_ID );
+	$size_slug      = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail';
+	$post_title     = trim( strip_tags( get_the_title( $post_ID ) ) );
+	$featured_image = get_the_post_thumbnail( $post_ID, $size_slug, array( 'alt' => $post_title ) );
 	if ( ! $featured_image ) {
 		return '';
 	}
-
+	$wrapper_attributes = get_block_wrapper_attributes();
 	if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
 		$featured_image = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $post_ID ), $featured_image );
 	}
 
-	$wrapper_attributes = get_block_wrapper_attributes();
+	$has_width  = ! empty( $attributes['width'] );
+	$has_height = ! empty( $attributes['height'] );
+	if ( ! $has_height && ! $has_width ) {
+		return "<figure $wrapper_attributes>$featured_image</figure>";
+	}
+
+	if ( $has_width ) {
+		$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => "width:{$attributes['width']};" ) );
+	}
 
-	return '<figure ' . $wrapper_attributes . '>' . $featured_image . '</figure>';
+	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 );
+	}
+
+	return "<figure $wrapper_attributes>$featured_image</figure>";
 }
 
 /**