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.
Метод класса: Personalizer{}
Хуков нет.
Возвращает
string.
Использование
// private - только в коде основоного (родительского) класса $result = $this->replace_link_href( $content, $token, $replacement );
- $content(строка) (обязательный)
- The content to replace the link href.
- $token(строка) (обязательный)
- Personalization tag token.
- $replacement(строка) (обязательный)
- The callback output to replace the link href.
Код Personalizer::replace_link_href() Personalizer::replace link href WC 11.2.2
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+[^\]]+)?\]/';
// Escape `$` and `\` so they are inserted literally instead of being interpreted as backreferences.
return trim( (string) preg_replace( $pattern, addcslashes( $replacement, '\\$' ), $content ) );
}