MailPoet\EmailEditor\Engine

Personalizer::replace_link_href()privateWC 1.0

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.

Return

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() code WC 9.8.1

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