BP_Email::set_tokens( string[] $tokens )

Set token names and replacement values for this email.


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.



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




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 BuddyPress 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;


Version Description
BuddyPress 2.5.0 Introduced.


We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.