Personalizer
in package
Class for replacing personalization tags with their values in the email content.
Table of Contents
- $context : array<string|int, mixed>
- Context for personalization tags.
- $tags_registry : Personalization_Tags_Registry
- Personalization tags registry.
- __construct() : mixed
- Class constructor with required dependencies.
- personalize_content() : string
- Personalize the content by replacing the personalization tags with their values.
- set_context() : void
- Set the context for personalization.
- parse_token() : array{token: string, arguments: array}
- Parse a personalization tag to the token and attributes.
- replace_link_href() : string
- Replace the href attribute of the anchor tag with the personalized value.
Properties
$context
Context for personalization tags.
private
array<string|int, mixed>
$context
The context
is an associative array containing recipient-specific or
campaign-specific data. This data is used to resolve personalization tags
and provide input for tag callbacks during email content processing.
Example context: array( 'recipient_email' => 'john@example.com', // Recipient's email 'custom_field' => 'Special Value', // Custom campaign-specific data )
$tags_registry
Personalization tags registry.
private
Personalization_Tags_Registry
$tags_registry
Methods
__construct()
Class constructor with required dependencies.
public
__construct(Personalization_Tags_Registry $tags_registry) : mixed
Parameters
- $tags_registry : Personalization_Tags_Registry
-
Personalization tags registry.
Return values
mixed —personalize_content()
Personalize the content by replacing the personalization tags with their values.
public
personalize_content(string $content) : string
Parameters
- $content : string
-
The content to personalize.
Return values
string — The personalized content.set_context()
Set the context for personalization.
public
set_context(array<string, mixed> $context) : void
The context
provides data required for resolving personalization tags
during content processing. This method allows the context to be set or updated.
Example usage: $personalizer->set_context(array( 'recipient_email' => 'john@example.com', ));
Parameters
- $context : array<string, mixed>
-
Associative array containing personalization data.
Return values
void —parse_token()
Parse a personalization tag to the token and attributes.
private
parse_token(string $token) : array{token: string, arguments: array}
Parameters
- $token : string
-
The token to parse.
Return values
array{token: string, arguments: array} — The parsed token.replace_link_href()
Replace the href attribute of the anchor tag with the personalized value.
private
replace_link_href(string $content, string $token, string $replacement) : string
The replacement uses regular expression to match the shortcode and its attributes.
Parameters
- $content : string
-
The content to replace the link href.
- $token : string
-
Personalization tag token.
- $replacement : string
-
The callback output to replace the link href.