bp_email_set_default_headers( array $headers, string $property, string $transform, BP_Email $email )

Add custom headers to outgoing emails.

Description

Parameters

$headers

(array) (Required) Array of email headers.

$property

(string) (Required) Name of property. Unused.

$transform

(string) (Required) Return value transformation. Unused.

$email

(BP_Email) (Required) Email object reference.

Return

(array)

Source

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

function bp_email_set_default_headers( $headers, $property, $transform, $email ) {
	$headers['X-BuddyPress']      = bp_get_version();
	$headers['X-BuddyPress-Type'] = $email->get( 'type' );

	$tokens = $email->get_tokens();

	// Add 'List-Unsubscribe' header if applicable.
	if ( ! empty( $tokens['unsubscribe'] ) && $tokens['unsubscribe'] !== wp_login_url() ) {
		$user = get_user_by( 'email', $tokens['recipient.email'] );

		$link = bp_email_get_unsubscribe_link( array(
			'user_id'           => $user->ID,
			'notification_type' => $email->get( 'type' ),
		) );

		if ( ! empty( $link ) ) {
			$headers['List-Unsubscribe'] = sprintf( '<%s>', esc_url_raw( $link ) );
		}
	}

	return $headers;
}

Changelog

Changelog
Version Description
BuddyPress 2.5.0 Introduced.

Questions?

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.