BP_Email::set_tokens( string[] $tokens )

Set token names and replacement values for this email.


Description Description

In templates, tokens are inserted with a Handlebars-like syntax, e.g. {{token_name}}. { and } are reserved characters. There’s no need to specify these brackets in your token names.


Parameters Parameters

$tokens

(Required) Associative array, contains key/value pairs of token name/value. Values are a string or a callable function.


Top ↑

Return Return

(BP_Email)


Top ↑

Source Source

File: bp-core/classes/class-bp-email.php

	public function set_tokens( array $tokens ) {
		$formatted_tokens = array();

		foreach ( $tokens as $name => $value ) {
			$name                      = str_replace( array( '{', '}' ), '', sanitize_text_field( $name ) );
			$formatted_tokens[ $name ] = $value;
		}

		/**
		 * Filters the new value of the email's "tokens" property.
		 *
		 * @since 2.5.0
		 *
		 * @param string[] $formatted_tokens Associative pairing of token names (key)
		 *                                   and replacement values (value).
		 * @param string[] $tokens           Associative pairing of unformatted token
		 *                                   names (key) and replacement values (value).
		 * @param BP_Email $this             Current instance of the email type class.
		 */
		$this->tokens = apply_filters( 'bp_email_set_tokens', $formatted_tokens, $tokens, $this );

		return $this;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.