Automattic\WooCommerce\EmailEditor\Engine
Personalizer::replace_link_href
Replace the href attribute of the anchor tag with the personalized value. The replacement uses regular expression to match the shortcode and its attributes.
Method of the class: Personalizer{}
No Hooks.
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->replace_link_href( $content, $token, $replacement );
- $content(string) (required)
- The content to replace the link href.
- $token(string) (required)
- Personalization tag token.
- $replacement(string) (required)
- The callback output to replace the link href.
Personalizer::replace_link_href() Personalizer::replace link href code WC 10.5.0
private function replace_link_href( string $content, string $token, string $replacement ) {
// Escape the shortcode name for safe regex usage and strip the brackets.
$escaped_shortcode = preg_quote( substr( $token, 1, strlen( $token ) - 2 ), '/' );
// Create a regex pattern dynamically.
$pattern = '/\[' . $escaped_shortcode . '(?:\s+[^\]]+)?\]/';
return trim( (string) preg_replace( $pattern, $replacement, $content ) );
}