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

Add custom headers to outgoing emails.


Parameters 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.


Top ↑

Return Return

(array)


Source 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'] );
		$user_id = isset( $user->ID ) ? $user->ID : 0;

		$args = array(
			'user_id'           => $user_id,
			'notification_type' => $email->get( 'type' ),
		);

		// If this email is not to a current member, include the nonmember's email address and the Inviter ID.
		if ( ! $user_id ) {
			$args['email_address'] = $tokens['recipient.email'];
			$args['member_id']     = bp_loggedin_user_id();
		}

		$link = bp_email_get_unsubscribe_link( $args );

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

	return $headers;
}


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.