bp_email_set_default_tokens( array $tokens, string $property_name, string $transform, BP_Email $email )

Add default email tokens.


Parameters Parameters

$tokens

(array) (Required) Email tokens.

$property_name

(string) (Required) Unused.

$transform

(string) (Required) Unused.

$email

(BP_Email) (Required) Email being sent.


Top ↑

Return Return

(array)


Source Source

File: bp-core/bp-core-filters.php

function bp_email_set_default_tokens( $tokens, $property_name, $transform, $email ) {
	$tokens['site.admin-email'] = bp_get_option( 'admin_email' );
	$tokens['site.url']         = bp_get_root_domain();
	$tokens['email.subject']    = $email->get_subject();

	// These options are escaped with esc_html on the way into the database in sanitize_option().
	$tokens['site.description'] = wp_specialchars_decode( bp_get_option( 'blogdescription' ), ENT_QUOTES );
	$tokens['site.name']        = wp_specialchars_decode( bp_get_option( 'blogname' ), ENT_QUOTES );

	// Default values for tokens set conditionally below.
	$tokens['email.preheader']     = '';
	$tokens['recipient.email']     = '';
	$tokens['recipient.name']      = '';
	$tokens['recipient.username']  = '';

	// Who is the email going to?
	$recipient = $email->get( 'to' );
	if ( $recipient ) {
		$recipient = array_shift( $recipient );
		$user_obj  = $recipient->get_user( 'search-email' );

		$tokens['recipient.email'] = $recipient->get_address();
		$tokens['recipient.name']  = $recipient->get_name();

		if ( ! $user_obj && $tokens['recipient.email'] ) {
			$user_obj = get_user_by( 'email', $tokens['recipient.email'] );
		}

		if ( $user_obj ) {
			$tokens['recipient.username'] = $user_obj->user_login;

			if ( bp_is_active( 'settings' ) && empty( $tokens['unsubscribe'] ) ) {
				$tokens['unsubscribe'] = esc_url( sprintf(
					'%s%s/notifications/',
					bp_core_get_user_domain( $user_obj->ID ),
					bp_get_settings_slug()
				) );
			}
		}
	}

	// Set default unsubscribe link if not passed.
	if ( empty( $tokens['unsubscribe'] ) ) {
		$tokens['unsubscribe'] = wp_login_url();
	}

	// Email preheader.
	$preheader = $email->get_preheader();
	if ( $preheader ) {
		$tokens['email.preheader'] = $preheader;
	}

	return $tokens;
}


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.