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

Add custom headers to outgoing emails.

Description

Parameters

$headers

(Required) Array of email headers.

$property

(Required) Name of property. Unused.

$transform

(Required) Return value transformation. Unused.

$email

(Required) Email object reference.

Return

(array)

Source

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

1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
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.