Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\Emails\Schema

EmailsSettingsSchema::unwrap_woocommerce_tags │ private │ WC 1.0

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.

Метод класса: EmailsSettingsSchema{}

Хуков нет.

Возвращает

string. The unwrapped value.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->unwrap_woocommerce_tags( $value );
$value(строка) (обязательный)
The value to unwrap.

Код EmailsSettingsSchema::unwrap_woocommerce_tags() WC 11.2.2

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;
}