Html_Processing_Helper
in package
Helper class for HTML processing and manipulation.
Table of Contents
- clean_css_classes() : string
- Clean CSS classes by removing background and border related classes.
- get_caption_css_properties() : array<string|int, mixed>
- Get list of safe CSS properties for caption typography (excludes background properties).
- get_safe_css_properties() : array<string|int, mixed>
- Get list of safe CSS properties for typography and basic styling.
- sanitize_caption_html() : string
- Sanitize caption HTML to allow only specific tags and attributes.
- sanitize_color() : string
- Sanitize color value to ensure it's a valid color format.
- sanitize_css_value() : string
- Sanitize CSS value to prevent injection attacks.
- sanitize_dimension_value() : string
- Sanitize dimension value to ensure it's a valid CSS dimension.
- sanitize_image_html() : string
- Sanitize image HTML while preserving necessary attributes for email rendering.
- validate_caption_attribute() : void
- Validate and sanitize specific caption attributes for security.
- validate_container_attributes() : bool
- Validate HTML container attributes for security before content extraction.
- normalize_rel_attribute() : string
- Normalize rel attribute by lowercasing, deduplicating tokens, and ensuring required tokens.
- sanitize_image_styles() : string
- Sanitize inline styles for image elements - only allow safe properties for email rendering.
Methods
clean_css_classes()
Clean CSS classes by removing background and border related classes.
public
static clean_css_classes(string $classes) : string
Parameters
- $classes : string
-
CSS classes to clean.
Return values
string — Cleaned CSS classes.get_caption_css_properties()
Get list of safe CSS properties for caption typography (excludes background properties).
public
static get_caption_css_properties() : array<string|int, mixed>
Return values
array<string|int, mixed> — Array of safe CSS property names for captions.get_safe_css_properties()
Get list of safe CSS properties for typography and basic styling.
public
static get_safe_css_properties() : array<string|int, mixed>
Return values
array<string|int, mixed> — Array of safe CSS property names.sanitize_caption_html()
Sanitize caption HTML to allow only specific tags and attributes.
public
static sanitize_caption_html(string $caption_html) : string
Parameters
- $caption_html : string
-
Raw caption HTML.
Return values
string — Sanitized caption HTML.sanitize_color()
Sanitize color value to ensure it's a valid color format.
public
static sanitize_color(string $color) : string
Supports hex colors, rgb/rgba, hsl/hsla, named colors, and CSS variables.
Parameters
- $color : string
-
The color value to sanitize.
Return values
string — Sanitized color value or safe default if invalid.sanitize_css_value()
Sanitize CSS value to prevent injection attacks.
public
static sanitize_css_value(string $value) : string
Parameters
- $value : string
-
CSS value to sanitize.
Return values
string — Sanitized CSS value or empty string if invalid.sanitize_dimension_value()
Sanitize dimension value to ensure it's a valid CSS dimension.
public
static sanitize_dimension_value(mixed $value) : string
Supports numeric values (converted to px) and standard CSS units.
Parameters
- $value : mixed
-
The dimension value to sanitize.
Return values
string — Sanitized dimension value or empty string if invalid.sanitize_image_html()
Sanitize image HTML while preserving necessary attributes for email rendering.
public
static sanitize_image_html(string $image_html) : string
Parameters
- $image_html : string
-
Raw image HTML.
Return values
string — Sanitized image HTML.validate_caption_attribute()
Validate and sanitize specific caption attributes for security.
public
static validate_caption_attribute(WP_HTML_Tag_Processor $html, string $attr_name) : void
Parameters
- $html : WP_HTML_Tag_Processor
-
HTML tag processor.
- $attr_name : string
-
Attribute name to validate.
Return values
void —validate_container_attributes()
Validate HTML container attributes for security before content extraction.
public
static validate_container_attributes(string $container_html) : bool
This method checks if a container element (like figcaption, span) has safe attributes.
Parameters
- $container_html : string
-
Full container HTML (e.g.,
content ).
Return values
bool — True if container attributes are safe, false otherwise.normalize_rel_attribute()
Normalize rel attribute by lowercasing, deduplicating tokens, and ensuring required tokens.
private
static normalize_rel_attribute(string|null $rel_value[, bool $require_security_tokens = false ]) : string
Parameters
- $rel_value : string|null
-
Current rel attribute value.
- $require_security_tokens : bool = false
-
Whether to require noopener and noreferrer tokens.
Return values
string — Normalized rel attribute value.sanitize_image_styles()
Sanitize inline styles for image elements - only allow safe properties for email rendering.
private
static sanitize_image_styles(string $style_value) : string
Parameters
- $style_value : string
-
Raw style value.
