MailPoet\EmailEditor\Engine\PersonalizationTags

Personalization_Tag::__construct()publicWC 1.0

Personalization_Tag constructor.

Example usage: $tag = new Personalization_Tag(

'First Name',
'user:first_name',
'User',
 function( $context, $args ) {
   return $context['user_firstname'] ?? 'user';
 },
 array( default => 'user' ),
 'user:first default="user"'

);

Method of the class: Personalization_Tag{}

No Hooks.

Return

null. Nothing (null).

Usage

$Personalization_Tag = new Personalization_Tag();
$Personalization_Tag->__construct(;

Personalization_Tag::__construct() code WC 9.8.2

public function __construct(
	string $name,
	string $token,
	string $category,
	callable $callback,
	array $attributes = array(),
	?string $value_to_insert = null
) {
	$this->name = $name;
	// Because Gutenberg does not wrap the token with square brackets, we need to add them here.
	$this->token      = strpos( $token, '[' ) === 0 ? $token : "[$token]";
	$this->category   = $category;
	$this->callback   = $callback;
	$this->attributes = $attributes;
	// Composing token to insert based on the token and attributes if it is not set.
	if ( ! $value_to_insert ) {
		if ( $this->attributes ) {
			$value_to_insert = substr( $this->token, 0, -1 ) . ' ' .
				implode(
					' ',
					array_map(
						function ( $key ) {
							return $key . '="' . esc_attr( $this->attributes[ $key ] ) . '"';
						},
						array_keys( $this->attributes )
					)
				) . ']';
		} else {
			$value_to_insert = $this->token;
		}
	}
	$this->value_to_insert = $value_to_insert;
}