Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors
Variables_Postprocessor::postprocess
Postprocess the HTML.
Method of the class: Variables_Postprocessor{}
No Hooks.
Returns
String.
Usage
$Variables_Postprocessor = new Variables_Postprocessor(); $Variables_Postprocessor->postprocess( $html ): string;
- $html(string) (required)
- HTML to postprocess.
Variables_Postprocessor::postprocess() Variables Postprocessor::postprocess code WC 10.7.0
public function postprocess( string $html ): string {
$variables = $this->theme_controller->get_variables_values_map();
$replacements = array();
foreach ( $variables as $name => $value ) {
$var_pattern = '/' . preg_quote( 'var(' . $name . ')', '/' ) . '/i';
$replacements[ $var_pattern ] = $value;
}
// We want to replace the CSS variables only in the style attributes to avoid replacing the actual content.
$processor = new \WP_HTML_Tag_Processor( $html );
while ( $processor->next_tag() ) {
$style = $processor->get_attribute( 'style' );
if ( null !== $style && true !== $style ) {
// Replace CSS variables with their values.
$processed_style = preg_replace( array_keys( $replacements ), array_values( $replacements ), $style );
if ( null !== $processed_style ) {
$processor->set_attribute( 'style', $processed_style );
}
}
}
return $processor->get_updated_html();
}