render_block_core_post_featured_image

The timeline below displays how wordpress function render_block_core_post_featured_image has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    $is_link = isset($attributes['isLink']) && $attributes['isLink'];
    $size_slug = isset($attributes['sizeSlug']) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $attr = get_block_core_post_featured_image_border_attributes($attributes);
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup($attributes);
    if ($is_link) {
        if (get_the_title($post_ID)) {
            $attr['alt'] = trim(strip_tags(get_the_title($post_ID)));
        } else {
            $attr['alt'] = sprintf(
                // translators: %d is the post ID.
                __('Untitled post %d'),
                $post_ID
            );
        }
    }
    $extra_styles = '';
    // Aspect ratio with a height set needs to override the default width/height.
    if (!empty($attributes['aspectRatio'])) {
        $extra_styles .= 'width:100%;height:100%;';
    } elseif (!empty($attributes['height'])) {
        $extra_styles .= "height:{$attributes['height']};";
    }
    if (!empty($attributes['scale'])) {
        $extra_styles .= "object-fit:{$attributes['scale']};";
    }
    if (!empty($extra_styles)) {
        $attr['style'] = empty($attr['style']) ? $extra_styles : ($attr['style'] . $extra_styles);
    }
    $featured_image = get_the_post_thumbnail($post_ID, $size_slug, $attr);
    // Get the first image from the post.
    if ($attributes['useFirstImageFromPost'] && !$featured_image) {
        $content_post = get_post($post_ID);
        $content = $content_post->post_content;
        $processor = new WP_HTML_Tag_Processor($content);
        /*
         * Transfer the image tag from the post into a new text snippet.
         * Because the HTML API doesn't currently expose a way to extract
         * HTML substrings this is necessary as a workaround. Of note, this
         * is different than directly extracting the IMG tag:
         * - If there are duplicate attributes in the source there will only be one in the output.
         * - If there are single-quoted or unquoted attributes they will be double-quoted in the output.
         * - If there are named character references in the attribute values they may be replaced with their direct code points. E.g. `…` becomes `…`.
         * In the future there will likely be a mechanism to copy snippets of HTML from
         * one document into another, via the HTML Processor's `get_outer_html()` or
         * equivalent. When that happens it would be appropriate to replace this custom
         * code with that canonical code.
         */
        if ($processor->next_tag('img')) {
            $tag_html = new WP_HTML_Tag_Processor('<img>');
            $tag_html->next_tag();
            foreach ($processor->get_attribute_names_with_prefix('') as $name) {
                $tag_html->set_attribute($name, $processor->get_attribute($name));
            }
            $featured_image = $tag_html->get_updated_html();
        }
    }
    if (!$featured_image) {
        return '';
    }
    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:' . $attributes['height'])) . '"' : '';
        $featured_image = sprintf('<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;
    }
    $aspect_ratio = (!empty($attributes['aspectRatio'])) ? esc_attr(safecss_filter_attr('aspect-ratio:' . $attributes['aspectRatio'])) . ';' : '';
    $width = (!empty($attributes['width'])) ? esc_attr(safecss_filter_attr('width:' . $attributes['width'])) . ';' : '';
    $height = (!empty($attributes['height'])) ? esc_attr(safecss_filter_attr('height:' . $attributes['height'])) . ';' : '';
    if (!$height && !$width && !$aspect_ratio) {
        $wrapper_attributes = get_block_wrapper_attributes();
    } else {
        $wrapper_attributes = get_block_wrapper_attributes(array('style' => $aspect_ratio . $width . $height));
    }
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 6.4

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    $is_link = isset($attributes['isLink']) && $attributes['isLink'];
    $size_slug = isset($attributes['sizeSlug']) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $attr = get_block_core_post_featured_image_border_attributes($attributes);
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup($attributes);
    if ($is_link) {
        if (get_the_title($post_ID)) {
            $attr['alt'] = trim(strip_tags(get_the_title($post_ID)));
        } else {
            $attr['alt'] = sprintf(
                // translators: %d is the post ID.
                __('Untitled post %d'),
                $post_ID
            );
        }
    }
    $extra_styles = '';
    // Aspect ratio with a height set needs to override the default width/height.
    if (!empty($attributes['aspectRatio'])) {
        $extra_styles .= 'width:100%;height:100%;';
    } elseif (!empty($attributes['height'])) {
        $extra_styles .= "height:{$attributes['height']};";
    }
    if (!empty($attributes['scale'])) {
        $extra_styles .= "object-fit:{$attributes['scale']};";
    }
    if (!empty($extra_styles)) {
        $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 '';
    }
    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:' . $attributes['height'])) . '"' : '';
        $featured_image = sprintf('<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;
    }
    $aspect_ratio = (!empty($attributes['aspectRatio'])) ? esc_attr(safecss_filter_attr('aspect-ratio:' . $attributes['aspectRatio'])) . ';' : '';
    $width = (!empty($attributes['width'])) ? esc_attr(safecss_filter_attr('width:' . $attributes['width'])) . ';' : '';
    $height = (!empty($attributes['height'])) ? esc_attr(safecss_filter_attr('height:' . $attributes['height'])) . ';' : '';
    if (!$height && !$width && !$aspect_ratio) {
        $wrapper_attributes = get_block_wrapper_attributes();
    } else {
        $wrapper_attributes = get_block_wrapper_attributes(array('style' => $aspect_ratio . $width . $height));
    }
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 6.3

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    // Check is needed for backward compatibility with third-party plugins
    // that might rely on the `in_the_loop` check; calling `the_post` sets it to true.
    if (!in_the_loop() && have_posts()) {
        the_post();
    }
    $is_link = isset($attributes['isLink']) && $attributes['isLink'];
    $size_slug = isset($attributes['sizeSlug']) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $attr = get_block_core_post_featured_image_border_attributes($attributes);
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup($attributes);
    if ($is_link) {
        if (get_the_title($post_ID)) {
            $attr['alt'] = trim(strip_tags(get_the_title($post_ID)));
        } else {
            $attr['alt'] = sprintf(
                // translators: %d is the post ID.
                __('Untitled post %d'),
                $post_ID
            );
        }
    }
    $extra_styles = '';
    // Aspect ratio with a height set needs to override the default width/height.
    if (!empty($attributes['aspectRatio'])) {
        $extra_styles .= 'width:100%;height:100%;';
    } elseif (!empty($attributes['height'])) {
        $extra_styles .= "height:{$attributes['height']};";
    }
    if (!empty($attributes['scale'])) {
        $extra_styles .= "object-fit:{$attributes['scale']};";
    }
    if (!empty($extra_styles)) {
        $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 '';
    }
    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:' . $attributes['height'])) . '"' : '';
        $featured_image = sprintf('<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;
    }
    $aspect_ratio = (!empty($attributes['aspectRatio'])) ? esc_attr(safecss_filter_attr('aspect-ratio:' . $attributes['aspectRatio'])) . ';' : '';
    $width = (!empty($attributes['width'])) ? esc_attr(safecss_filter_attr('width:' . $attributes['width'])) . ';' : '';
    $height = (!empty($attributes['height'])) ? esc_attr(safecss_filter_attr('height:' . $attributes['height'])) . ';' : '';
    if (!$height && !$width && !$aspect_ratio) {
        $wrapper_attributes = get_block_wrapper_attributes();
    } else {
        $wrapper_attributes = get_block_wrapper_attributes(array('style' => $aspect_ratio . $width . $height));
    }
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 6.2

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    // Check is needed for backward compatibility with third-party plugins
    // that might rely on the `in_the_loop` check; calling `the_post` sets it to true.
    if (!in_the_loop() && have_posts()) {
        the_post();
    }
    $is_link = isset($attributes['isLink']) && $attributes['isLink'];
    $size_slug = isset($attributes['sizeSlug']) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $attr = get_block_core_post_featured_image_border_attributes($attributes);
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup($attributes);
    if ($is_link) {
        if (get_the_title($post_ID)) {
            $attr['alt'] = trim(strip_tags(get_the_title($post_ID)));
        } else {
            $attr['alt'] = sprintf(
                // translators: %d is the post ID.
                __('Untitled post %d'),
                $post_ID
            );
        }
    }
    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 '';
    }
    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:' . $attributes['height'])) . '"' : '';
        $featured_image = sprintf('<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;
    }
    $width = (!empty($attributes['width'])) ? esc_attr(safecss_filter_attr('width:' . $attributes['width'])) . ';' : '';
    $height = (!empty($attributes['height'])) ? esc_attr(safecss_filter_attr('height:' . $attributes['height'])) . ';' : '';
    if (!$height && !$width) {
        $wrapper_attributes = get_block_wrapper_attributes();
    } else {
        $wrapper_attributes = get_block_wrapper_attributes(array('style' => $width . $height));
    }
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 1.3

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    // Check is needed for backward compatibility with third-party plugins
    // that might rely on the `in_the_loop` check; calling `the_post` sets it to true.
    if (!in_the_loop() && have_posts()) {
        the_post();
    }
    $is_link = isset($attributes['isLink']) && $attributes['isLink'];
    $size_slug = isset($attributes['sizeSlug']) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $post_title = trim(strip_tags(get_the_title($post_ID)));
    $attr = get_block_core_post_featured_image_border_attributes($attributes);
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup($attributes);
    if ($is_link) {
        $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 '';
    }
    if ($is_link) {
        $link_target = $attributes['linkTarget'];
        $rel = (!empty($attributes['rel'])) ? 'rel="' . esc_attr($attributes['rel']) . '"' : '';
        $featured_image = sprintf('<a href="%1$s" target="%2$s" %3$s>%4$s%5$s</a>', get_the_permalink($post_ID), esc_attr($link_target), $rel, $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']};"));
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 1.1

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    $is_link = isset($attributes['isLink']) && $attributes['isLink'];
    $size_slug = isset($attributes['sizeSlug']) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $post_title = trim(strip_tags(get_the_title($post_ID)));
    $attr = get_block_core_post_featured_image_border_attributes($attributes);
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup($attributes);
    if ($is_link) {
        $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 '';
    }
    if ($is_link) {
        $link_target = $attributes['linkTarget'];
        $rel = (!empty($attributes['rel'])) ? 'rel="' . esc_attr($attributes['rel']) . '"' : '';
        $featured_image = sprintf('<a href="%1$s" target="%2$s" %3$s>%4$s%5$s</a>', get_the_permalink($post_ID), esc_attr($link_target), $rel, $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']};"));
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 6.1

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    $is_link = isset($attributes['isLink']) && $attributes['isLink'];
    $size_slug = isset($attributes['sizeSlug']) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $post_title = trim(strip_tags(get_the_title($post_ID)));
    $attr = get_block_core_post_featured_image_border_attributes($attributes);
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup($attributes);
    if ($is_link) {
        $attr['alt'] = $post_title;
    }
    $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']) . '"' : '';
        $featured_image = sprintf('<a href="%1$s" target="%2$s" %3$s>%4$s%5$s</a>', get_the_permalink($post_ID), esc_attr($link_target), $rel, $featured_image, $overlay_markup);
    } else {
        $featured_image = $featured_image . $overlay_markup;
    }
    $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']};"));
    }
    if ($has_height) {
        $image_styles = "height:{$attributes['height']};";
        if (!empty($attributes['scale'])) {
            $image_styles .= "object-fit:{$attributes['scale']};";
        }
        $featured_image = str_replace('<img ', '<img style="' . esc_attr(safecss_filter_attr($image_styles)) . '" ', $featured_image);
    }
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 9.5

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    $featured_image = get_the_post_thumbnail($post_ID);
    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);
    }
    $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']};"));
    }
    if ($has_height) {
        $image_styles = "height:{$attributes['height']};";
        if (!empty($attributes['scale'])) {
            $image_styles .= "object-fit:{$attributes['scale']};";
        }
        $featured_image = str_replace('<img ', '<img style="' . esc_attr(safecss_filter_attr($image_styles)) . '" ', $featured_image);
    }
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 5.9

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    $featured_image = get_the_post_thumbnail($post_ID);
    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);
    }
    $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']};"));
    }
    if ($has_height) {
        $image_styles = "height:{$attributes['height']};";
        if (!empty($attributes['scale'])) {
            $image_styles .= "object-fit:{$attributes['scale']};";
        }
        $featured_image = str_replace('src=', "style='{$image_styles}' src=", $featured_image);
    }
    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

WordPress Version: 5.8

/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image($attributes, $content, $block)
{
    if (!isset($block->context['postId'])) {
        return '';
    }
    $post_ID = $block->context['postId'];
    $featured_image = get_the_post_thumbnail($post_ID);
    if (!$featured_image) {
        return '';
    }
    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();
    return '<figure ' . $wrapper_attributes . '>' . $featured_image . '</figure>';
}