MailPoet\EmailEditor\Engine
Personalizer::personalize_content()
Personalize the content by replacing the personalization tags with their values.
Method of the class: Personalizer{}
No Hooks.
Return
String
. The personalized content.
Usage
$Personalizer = new Personalizer(); $Personalizer->personalize_content( $content ): string;
- $content(string) (required)
- The content to personalize.
Personalizer::personalize_content() Personalizer::personalize content code WC 9.8.1
public function personalize_content( string $content ): string { $content_processor = new HTML_Tag_Processor( $content ); while ( $content_processor->next_token() ) { if ( $content_processor->get_token_type() === '#comment' ) { $token = $this->parse_token( $content_processor->get_modifiable_text() ); $tag = $this->tags_registry->get_by_token( $token['token'] ); if ( ! $tag ) { continue; } $value = $tag->execute_callback( $this->context, $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 ); } elseif ( $content_processor->get_token_type() === '#tag' && $content_processor->get_tag() === 'A' && $content_processor->get_attribute( 'data-link-href' ) ) { // The anchor tag contains the data-link-href attribute which should be personalized. $href = $content_processor->get_attribute( 'data-link-href' ); $token = $this->parse_token( $href ); $tag = $this->tags_registry->get_by_token( $token['token'] ); if ( ! $tag ) { continue; } $value = $tag->execute_callback( $this->context, $token['arguments'] ); $value = $this->replace_link_href( $href, $tag->get_token(), $value ); if ( $value ) { $content_processor->set_attribute( 'href', $value ); $content_processor->remove_attribute( 'data-link-href' ); $content_processor->remove_attribute( 'contenteditable' ); } } } $content_processor->flush_updates(); return $content_processor->get_updated_html(); }