Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\Emails\Schema
EmailsSettingsSchema::wrap_woocommerce_tags
Wrap personalization tags in HTML comments for the email editor. This is required for the email editor personalization. Use negative lookbehind and lookahead to avoid double-wrapping already wrapped tags.
Method of the class: EmailsSettingsSchema{}
No Hooks.
Returns
Mixed. The wrapped value.
Usage
// private - for code of main (parent) class only $result = $this->wrap_woocommerce_tags( $value );
- $value(mixed) (required)
- The value to wrap.
EmailsSettingsSchema::wrap_woocommerce_tags() EmailsSettingsSchema::wrap woocommerce tags code WC 10.4.3
private function wrap_woocommerce_tags( $value ) {
if ( ! is_string( $value ) ) {
return $value;
}
$prefixes = $this->get_personalization_tag_prefixes();
if ( empty( $prefixes ) ) {
return $value;
}
// Escape prefixes for use in regex and join with |.
$escaped_prefixes = array_map( 'preg_quote', $prefixes );
$prefixes_pattern = implode( '|', $escaped_prefixes );
// Wrap tags that aren't already wrapped.
return preg_replace( '/(?<!<!--)(\[(?:' . $prefixes_pattern . ')\/[^\]]+\])(?!-->)/i', '<!--$1-->', $value );
}