Add Personalization Tags support for title
[MAILPOET-6328]
This commit is contained in:
@@ -65,6 +65,11 @@ class Personalizer {
|
||||
|
||||
$value = call_user_func( $tag['callback'], ...array_merge( array( $this->context ), array( 'args' => $token ['arguments'] ) ) );
|
||||
$content_processor->replace_token( $value );
|
||||
|
||||
} elseif ( $content_processor->get_token_type() === '#tag' && $content_processor->get_tag() === 'TITLE' ) {
|
||||
// The title tag contains the subject of the email which should be personalized. HTML_Tag_Processor does parse the header tags.
|
||||
$title = $this->personalize_content( $content_processor->get_modifiable_text() );
|
||||
$content_processor->set_modifiable_text( $title );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -129,4 +129,41 @@ class PersonalizerIntegrationTest extends \MailPoetTest {
|
||||
$html_content = '<p>Hello, <!--user/firstname default="Guest"-->!</p>';
|
||||
$this->assertSame( '<p>Hello, Guest!</p>', $this->personalizer->personalize_content( $html_content ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a callback arguments.
|
||||
*/
|
||||
public function testPersonalizationInTitle(): void {
|
||||
$this->tags_registry->register(
|
||||
'default_name',
|
||||
'user/firstname',
|
||||
'Subscriber Info',
|
||||
function ( $context, $args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- The $args parameter is not used in this test.
|
||||
return $context['user_name'] ?? 'Default Name';
|
||||
}
|
||||
);
|
||||
|
||||
$html_content = '
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome, <!--user/firstname default="Guest"-->!</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello, <!--user/firstname default="Guest"-->!</p>
|
||||
</html>
|
||||
';
|
||||
$this->personalizer->set_context( array( 'user_name' => 'John' ) );
|
||||
$this->assertSame(
|
||||
'
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome, John!</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello, John!</p>
|
||||
</html>
|
||||
',
|
||||
$this->personalizer->personalize_content( $html_content )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user