WooCommerce Code Reference

Image extends Abstract_Block_Renderer
in package

Renders an image block.

Table of Contents

render()  : string
Render the block.
add_spacer()  : string
Add a spacer around the block.
compile_css()  : string
Compile objects containing CSS properties to a string.
get_inner_content()  : string
Extract inner content from a wrapper element.
get_styles_from_block()  : array<string|int, mixed>
Wrapper for wp_style_engine_get_styles which ensures all values are returned.
render_content()  : string
Renders the block content
add_image_dimensions()  : string
Settings width and height attributes for images is important for MS Outlook.
add_image_size_when_missing()  : array<string|int, mixed>
When the width is not set, it's important to get it for the image to be displayed correctly
add_style_to_element()  : string
Add style to the element.
apply_image_border_style()  : string
Apply border style to the image.
apply_rounded_style()  : string
Apply rounded style to the image.
cleanup_image_html()  : string
Cleanup image HTML.
get_block_wrapper()  : string
Based on MJML <mj-image> but because MJML doesn't support captions, our solution is a bit different
get_caption_styles()  : string
This method configure the font size of the caption because it's set to 0 for the parent element to avoid unexpected white spaces We try to use font-size passed down from the parent element $parsedBlock['email_attrs']['font-size'], but if it's not set, we use the default font-size from the email theme.
parse_block_content()  : array{imageUrl: string, image: string, caption: string, class: string, anchor_tag_href: string}|null
Parse block content to get image URL, image HTML and caption HTML.
remove_style_attribute_from_element()  : string
Remove style attribute from the element.

Methods

get_inner_content()

Extract inner content from a wrapper element.

protected get_inner_content(string $block_content[, string $tag_name = 'div' ]) : string

Removes the outer wrapper element (e.g., div) and returns only the inner HTML content. This is useful when you need to strip the wrapper and use only the inner content.

Parameters
$block_content : string

Block content with wrapper element.

$tag_name : string = 'div'

Tag name of the wrapper element (default: 'div').

Return values
stringInner content without the wrapper element, or original content if wrapper not found.

get_styles_from_block()

Wrapper for wp_style_engine_get_styles which ensures all values are returned.

protected get_styles_from_block(array<string|int, mixed> $block_styles[, bool $skip_convert_vars = false ]) : array<string|int, mixed>
Parameters
$block_styles : array<string|int, mixed>

Array of block styles.

$skip_convert_vars : bool = false

If true, --wp_preset--spacing--x type values will be left in the original var:preset:spacing:x format.

Return values
array<string|int, mixed>

add_image_dimensions()

Settings width and height attributes for images is important for MS Outlook.

private add_image_dimensions(string $block_content, array<string|int, mixed> $parsed_block) : string
Parameters
$block_content : string

Block content.

$parsed_block : array<string|int, mixed>

Parsed block.

Return values
string

add_image_size_when_missing()

When the width is not set, it's important to get it for the image to be displayed correctly

private add_image_size_when_missing(array<string|int, mixed> $parsed_block, string $image_url) : array<string|int, mixed>
Parameters
$parsed_block : array<string|int, mixed>

Parsed block.

$image_url : string

Image URL.

Return values
array<string|int, mixed>

add_style_to_element()

Add style to the element.

private add_style_to_element(string $block_content, array{tag_name: string, class_name?: string} $tag, string $style) : string
Parameters
$block_content : string

Block content.

$tag : array{tag_name: string, class_name?: string}

Tag to add style to.

$style : string

Style to add.

Return values
string

apply_image_border_style()

Apply border style to the image.

private apply_image_border_style(string $block_content, array<string|int, mixed> $parsed_block, string $class_name) : string
Parameters
$block_content : string

Block content.

$parsed_block : array<string|int, mixed>

Parsed block.

$class_name : string

Class name.

Return values
string

get_block_wrapper()

Based on MJML <mj-image> but because MJML doesn't support captions, our solution is a bit different

private get_block_wrapper(array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context, string|null $caption, string|null $anchor_tag_href) : string
Parameters
$parsed_block : array<string|int, mixed>

Parsed block.

$rendering_context : Rendering_Context

Rendering context.

$caption : string|null

Caption.

$anchor_tag_href : string|null

Anchor tag href.

Return values
string

get_caption_styles()

This method configure the font size of the caption because it's set to 0 for the parent element to avoid unexpected white spaces We try to use font-size passed down from the parent element $parsedBlock['email_attrs']['font-size'], but if it's not set, we use the default font-size from the email theme.

private get_caption_styles(Rendering_Context $rendering_context, array<string|int, mixed> $parsed_block) : string
Parameters
$rendering_context : Rendering_Context

Rendering context.

$parsed_block : array<string|int, mixed>

Parsed block.

Return values
string

parse_block_content()

Parse block content to get image URL, image HTML and caption HTML.

private parse_block_content(string $block_content) : array{imageUrl: string, image: string, caption: string, class: string, anchor_tag_href: string}|null
Parameters
$block_content : string

Block content.

Return values
array{imageUrl: string, image: string, caption: string, class: string, anchor_tag_href: string}|null

remove_style_attribute_from_element()

Remove style attribute from the element.

private remove_style_attribute_from_element(string $block_content, array{tag_name: string, class_name?: string} $tag, string $style_name) : string
Parameters
$block_content : string

Block content.

$tag : array{tag_name: string, class_name?: string}

Tag to remove style from.

$style_name : string

Name of the style to remove.

Return values
string