Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\Emails\Schema
EmailsSettingsSchema::unwrap_woocommerce_tags
Remove HTML comment wrappers from personalization tags.
Converts tags from <!--[prefix/tag-name]--> back to [prefix/tag-name] for all registered prefixes. For example: <!--[woocommerce/customer-name]--> becomes [woocommerce/customer-name].
This is required because the email editor personalization tags are wrapped in HTML comment wrappers. We need to remove the tags to make editing easier for the end-users and also because the tags are not well formatted in the current DataForm implementation.
Method of the class: EmailsSettingsSchema{}
No Hooks.
Returns
String. The unwrapped value.
Usage
// private - for code of main (parent) class only $result = $this->unwrap_woocommerce_tags( $value );
- $value(string) (required)
- The value to unwrap.
EmailsSettingsSchema::unwrap_woocommerce_tags() EmailsSettingsSchema::unwrap woocommerce tags code WC 10.4.3
private function unwrap_woocommerce_tags( $value ) {
if ( ! is_string( $value ) ) {
return $value;
}
// Get all registered prefixes dynamically.
$prefixes = $this->get_personalization_tag_prefixes();
// If no prefixes, return the value unchanged.
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 );
// Remove HTML comment wrappers from personalization tags.
$unwrapped_value = preg_replace( '/<!--(\[(?:' . $prefixes_pattern . ')\/[^\]]+\])-->/i', '$1', $value );
return $unwrapped_value;
}