Table
extends Abstract_Block_Renderer
in package
Renders a table block.
Table of Contents
- VALID_TEXT_ALIGNMENTS = array('left', 'center', 'right')
- Valid text alignment values.
- 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_class_to_table_element() : string
- Add a CSS class to the table element.
- add_header_footer_borders() : string
- Add thicker borders for table headers and footers when no custom border is set.
- apply_styles_to_table_element() : string
- Apply CSS styles directly to the table element.
- extract_table_and_caption_from_figure() : array<string|int, mixed>
- Extract table content and caption from figure wrapper if present.
- extract_typography_styles_for_caption() : string
- Extract typography styles from CSS string for caption.
- get_cell_text_alignment() : string
- Get text alignment for a table cell.
- get_custom_border_color() : string|null
- Get custom border color from block attributes.
- get_custom_border_style() : string
- Get custom border style from block attributes.
- get_custom_border_width() : string|null
- Get custom border width from block attributes.
- get_default_border_widths() : string
- Get default border widths for table element when individual border colors are present.
- has_fixed_layout() : bool
- Check if table has fixed layout class.
- is_striped_table() : bool
- Check if the table has striped styling.
- is_valid_table_content() : bool
- Validate if the content is a valid table HTML.
- process_table_content() : string
- Process table content to ensure email client compatibility.
Constants
VALID_TEXT_ALIGNMENTS
Valid text alignment values.
private
mixed
VALID_TEXT_ALIGNMENTS
= array('left', 'center', 'right')
Methods
render()
Render the block.
public
render(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string
Parameters
- $block_content : string
-
The block content.
- $parsed_block : array<string|int, mixed>
-
The parsed block.
- $rendering_context : Rendering_Context
-
The rendering context.
Return values
string —add_spacer()
Add a spacer around the block.
protected
add_spacer(string $content, array<string|int, mixed> $email_attrs) : string
Parameters
- $content : string
-
The block content.
- $email_attrs : array<string|int, mixed>
-
The email attributes.
Return values
string —compile_css()
Compile objects containing CSS properties to a string.
protected
compile_css(array<string|int, mixed> ...$styles) : string
Parameters
- $styles : array<string|int, mixed>
-
Style arrays to compile.
Return values
string —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
string — Inner 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> —render_content()
Renders the block content.
protected
render_content(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
string —add_class_to_table_element()
Add a CSS class to the table element.
private
add_class_to_table_element(string $table_content, string $class_name) : string
Parameters
- $table_content : string
-
Table HTML content.
- $class_name : string
-
CSS class to add.
Return values
string — Table content with class added.add_header_footer_borders()
Add thicker borders for table headers and footers when no custom border is set.
private
add_header_footer_borders(WP_HTML_Tag_Processor $html, string $base_styles, string $border_color[, string $current_section = '' ][, string|null $custom_border_width = null ]) : string
Parameters
- $html : WP_HTML_Tag_Processor
-
HTML tag processor.
- $base_styles : string
-
Base cell styles.
- $border_color : string
-
Border color.
- $current_section : string = ''
-
Current table section (thead, tbody, tfoot).
- $custom_border_width : string|null = null
-
Custom border width if set.
Return values
string — Updated cell styles.apply_styles_to_table_element()
Apply CSS styles directly to the table element.
private
apply_styles_to_table_element(string $table_content, string $styles) : string
Parameters
- $table_content : string
-
Table HTML content.
- $styles : string
-
CSS styles to apply.
Return values
string — Table content with styles applied.extract_table_and_caption_from_figure()
Extract table content and caption from figure wrapper if present.
private
extract_table_and_caption_from_figure(string $block_content) : array<string|int, mixed>
Parameters
- $block_content : string
-
Block content.
Return values
array<string|int, mixed> — Array with 'table' and 'caption' keys.extract_typography_styles_for_caption()
Extract typography styles from CSS string for caption.
private
extract_typography_styles_for_caption(string $css) : string
Parameters
- $css : string
-
CSS string to extract typography from.
Return values
string — Typography CSS for caption.get_cell_text_alignment()
Get text alignment for a table cell.
private
get_cell_text_alignment(WP_HTML_Tag_Processor $html) : string
Parameters
- $html : WP_HTML_Tag_Processor
-
HTML tag processor.
Return values
string — Text alignment value (left, center, right).get_custom_border_color()
Get custom border color from block attributes.
private
get_custom_border_color(array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string|null
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
string|null — Custom border color or null if not set.get_custom_border_style()
Get custom border style from block attributes.
private
get_custom_border_style(array<string|int, mixed> $parsed_block) : string
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block.
Return values
string — Custom border style or 'solid' as default.get_custom_border_width()
Get custom border width from block attributes.
private
get_custom_border_width(array<string|int, mixed> $parsed_block) : string|null
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block.
Return values
string|null — Custom border width or null if not set.get_default_border_widths()
Get default border widths for table element when individual border colors are present.
private
get_default_border_widths(string $existing_style) : string
Parameters
- $existing_style : string
-
Existing style attribute of the table element.
Return values
string — CSS border width styles or empty string if not needed.has_fixed_layout()
Check if table has fixed layout class.
private
has_fixed_layout(string $class_attr) : bool
Parameters
- $class_attr : string
-
Class attribute string.
Return values
bool — True if has-fixed-layout class is present.is_striped_table()
Check if the table has striped styling.
private
is_striped_table(string $block_content, array<string|int, mixed> $parsed_block) : bool
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
Return values
bool — True if it's a striped table, false otherwise.is_valid_table_content()
Validate if the content is a valid table HTML.
private
is_valid_table_content(string $content) : bool
Parameters
- $content : string
-
The content to validate.
Return values
bool — True if it's a valid table, false otherwise.process_table_content()
Process table content to ensure email client compatibility.
private
process_table_content(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context[, bool $is_striped_table = false ]) : string
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $rendering_context : Rendering_Context
-
Rendering context.
- $is_striped_table : bool = false
-
Whether this is a striped table.
