Content_Renderer
in package
Class Content_Renderer
Table of Contents
- CONTENT_STYLES_FILE = 'content.css'
- $backup_post : WP_Post|null
- Property to store the backup of the current post.
- $backup_post_content_callback : callable|null
- Backup of the original core/post-content render callback.
- $backup_query : WP_Query|null
- Property to store the backup of the current query.
- $backup_template_content : string|null
- Property to store the backup of the current template content.
- $backup_template_id : int|null
- Property to store the backup of the current template ID.
- $block_type_registry : WP_Block_Type_Registry
- WordPress Block Type Registry.
- $container_padding : array<string|int, mixed>
- Container padding from the template group wrapping post-content.
- $css_inliner : Css_Inliner
- CSS inliner
- $fallback_renderer : Fallback
- Fallback renderer that is used when render_email_callback is not set for the rendered blockType.
- $logger : Email_Editor_Logger
- Logger instance.
- $post_content_width : string|null
- Post-content block's calculated width from the first preprocessing pass.
- $process_manager : Process_Manager
- Process manager
- $theme_controller : Theme_Controller
- Theme controller
- __construct() : mixed
- Content_Renderer constructor.
- block_parser() : string
- Get block parser class
- preprocess_parsed_blocks() : array<string|int, mixed>
- Preprocess parsed blocks.
- render() : string
- Render the content with inlined CSS styles.
- render_block() : string
- Renders block Translates block's HTML to HTML suitable for email clients. The method is intended as a callback for 'render_block' filter.
- render_without_css_inline() : array{html: string, styles: string}
- Render the content and collect CSS styles without inlining them.
- add_root_horizontal_padding() : string
- Wrap block output with horizontal padding (root + container).
- collect_styles() : string
- Collects CSS for the rendered content without inlining it.
- find_container_padding() : array{left?: string, right?: string}
- Find the container padding from blocks with suppress-horizontal-padding flag.
- find_post_content_width() : string|null
- Recursively find the post-content block's width in preprocessed blocks.
- initialize() : void
- Initialize the content renderer
- reset() : void
- As we use default WordPress filters, we need to remove them after email rendering so that we don't interfere with possible post rendering that might happen later.
- resolve_preset_padding() : string
- Resolve a CSS value that may contain a preset variable reference.
- set_template_globals() : void
- Set template globals
- sum_padding_values() : float
- Sum two CSS pixel padding values.
Constants
CONTENT_STYLES_FILE
public
mixed
CONTENT_STYLES_FILE
= 'content.css'
Properties
$backup_post
Property to store the backup of the current post.
private
WP_Post|null
$backup_post
$backup_post_content_callback
Backup of the original core/post-content render callback.
private
callable|null
$backup_post_content_callback
$backup_query
Property to store the backup of the current query.
private
WP_Query|null
$backup_query
$backup_template_content
Property to store the backup of the current template content.
private
string|null
$backup_template_content
$backup_template_id
Property to store the backup of the current template ID.
private
int|null
$backup_template_id
$block_type_registry
WordPress Block Type Registry.
private
WP_Block_Type_Registry
$block_type_registry
$container_padding
Container padding from the template group wrapping post-content.
private
array<string|int, mixed>
$container_padding
= array()
Stored during the first preprocessing pass and passed to user blocks in the second pass so they receive the container padding per-block.
$css_inliner
CSS inliner
private
Css_Inliner
$css_inliner
$fallback_renderer
Fallback renderer that is used when render_email_callback is not set for the rendered blockType.
private
Fallback
$fallback_renderer
$logger
Logger instance.
private
Email_Editor_Logger
$logger
$post_content_width
Post-content block's calculated width from the first preprocessing pass.
private
string|null
$post_content_width
= null
When this is narrower than contentSize, it means root padding was applied to a container above post-content. In that case, the second preprocessing pass (user blocks) must skip root padding to prevent double application. When equal to contentSize, the template delegates root padding and user blocks should receive it directly.
$process_manager
Process manager
private
Process_Manager
$process_manager
$theme_controller
Theme controller
private
Theme_Controller
$theme_controller
Methods
__construct()
Content_Renderer constructor.
public
__construct(Process_Manager $preprocess_manager, Css_Inliner $css_inliner, Theme_Controller $theme_controller, Email_Editor_Logger $logger) : mixed
Parameters
- $preprocess_manager : Process_Manager
-
Preprocess manager.
- $css_inliner : Css_Inliner
-
CSS inliner.
- $theme_controller : Theme_Controller
-
Theme controller.
- $logger : Email_Editor_Logger
-
Logger instance.
Return values
mixed —block_parser()
Get block parser class
public
block_parser() : string
Return values
string —preprocess_parsed_blocks()
Preprocess parsed blocks.
public
preprocess_parsed_blocks(array<string|int, mixed> $parsed_blocks) : array<string|int, mixed>
Called for both template blocks and post-content user blocks. The Spacing_Preprocessor handles root padding distribution: container blocks (groups wrapping post-content) are transparent, delegating padding to their children so user blocks get individual padding.
Parameters
- $parsed_blocks : array<string|int, mixed>
-
Parsed blocks.
Return values
array<string|int, mixed> —render()
Render the content with inlined CSS styles.
public
render(WP_Post $post, WP_Block_Template $template) : string
Parameters
- $post : WP_Post
-
Post object.
- $template : WP_Block_Template
-
Block template.
Return values
string — Rendered HTML content with inlined styles.render_block()
Renders block Translates block's HTML to HTML suitable for email clients. The method is intended as a callback for 'render_block' filter.
public
render_block(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 —render_without_css_inline()
Render the content and collect CSS styles without inlining them.
public
render_without_css_inline(WP_Post $post, WP_Block_Template $template) : array{html: string, styles: string}
Parameters
- $post : WP_Post
-
Post object.
- $template : WP_Block_Template
-
Block template.
Tags
Return values
array{html: string, styles: string} — Rendered HTML and collected CSS.add_root_horizontal_padding()
Wrap block output with horizontal padding (root + container).
private
add_root_horizontal_padding(string $content, array<string|int, mixed> $email_attrs) : string
Root padding is distributed by the Spacing_Preprocessor from the outer email container to individual blocks. Container padding comes from template groups wrapping post-content. Both are combined into a single CSS padding wrapper. This method applies padding uniformly to all blocks regardless of whether they use Abstract_Block_Renderer or a custom render_email_callback.
Parameters
- $content : string
-
The rendered block content.
- $email_attrs : array<string|int, mixed>
-
The email attributes from the parsed block.
Return values
string — The content wrapped with horizontal padding, or unchanged if no padding.collect_styles()
Collects CSS for the rendered content without inlining it.
private
collect_styles(WP_Post $post[, WP_Block_Template|null $template = null ]) : string
Parameters
- $post : WP_Post
-
Post object.
- $template : WP_Block_Template|null = null
-
Block template.
Return values
string — The collected CSS string (without wrapper).find_container_padding()
Find the container padding from blocks with suppress-horizontal-padding flag.
private
find_container_padding(array<string|int, mixed> $blocks) : array{left?: string, right?: string}
Searches the preprocessed template blocks for a container that wraps post-content and had its horizontal padding distributed per-block.
Parameters
- $blocks : array<string|int, mixed>
-
Preprocessed blocks.
Return values
array{left?: string, right?: string} — Container padding values, or empty array.find_post_content_width()
Recursively find the post-content block's width in preprocessed blocks.
private
find_post_content_width(array<string|int, mixed> $blocks[, array<string|int, mixed>|null $post_content_block_names = null ]) : string|null
Parameters
- $blocks : array<string|int, mixed>
-
Preprocessed blocks.
- $post_content_block_names : array<string|int, mixed>|null = null
-
Cached block names for recursion.
Return values
string|null — The post-content block's width or null if not found.initialize()
Initialize the content renderer
private
initialize() : void
Return values
void —reset()
As we use default WordPress filters, we need to remove them after email rendering so that we don't interfere with possible post rendering that might happen later.
private
reset() : void
Return values
void —resolve_preset_padding()
Resolve a CSS value that may contain a preset variable reference.
private
resolve_preset_padding(string $value, array<string|int, mixed> $variables_map) : string
Block attributes store padding as preset references like "var:preset|spacing|20" which resolve to actual pixel values.
Parameters
- $value : string
-
The CSS value, possibly a preset reference.
- $variables_map : array<string|int, mixed>
-
Map of CSS variable names to resolved values.
Return values
string — The resolved value (e.g. "8px") or the original value.set_template_globals()
Set template globals
private
set_template_globals(WP_Post $email_post, WP_Block_Template $template) : void
Parameters
- $email_post : WP_Post
-
Post object.
- $template : WP_Block_Template
-
Block template.
Return values
void —sum_padding_values()
Sum two CSS pixel padding values.
private
sum_padding_values(string|null $value1, string|null $value2) : float
Parameters
- $value1 : string|null
-
First padding value (e.g., '20px').
- $value2 : string|null
-
Second padding value (e.g., '10px').
