WooCommerce Code Reference

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

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
stringSanitized color value or safe default 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
stringSanitized dimension value or empty string if invalid.

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
boolTrue 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
stringNormalized rel attribute value.