bp_email_set_default_headers

Add custom headers to outgoing emails.

Description

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

Returns (array)

Parameters (4)

0. $headers (array)
Array of email headers.
1. $property (string)
Name of property. Unused.
2. $transform (string)
Return value transformation. Unused.
3. $email (BP_Email)
Email object reference.

Usage

  1. if ( !function_exists( 'bp_email_set_default_headers' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-filters.php'; 
  3.  
  4. // Array of email headers. 
  5. $headers = array(); 
  6.  
  7. // Name of property. Unused. 
  8. $property = ''; 
  9.  
  10. // Return value transformation. Unused. 
  11. $transform = ''; 
  12.  
  13. // Email object reference. 
  14. $email = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bp_email_set_default_headers($headers, $property, $transform, $email); 
  18.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-filters.php  
  1. function bp_email_set_default_headers( $headers, $property, $transform, $email ) { 
  2. $headers['X-BuddyPress'] = bp_get_version(); 
  3. $headers['X-BuddyPress-Type'] = $email->get( 'type' ); 
  4.  
  5. $tokens = $email->get_tokens(); 
  6.  
  7. // Add 'List-Unsubscribe' header if applicable. 
  8. if ( ! empty( $tokens['unsubscribe'] ) && $tokens['unsubscribe'] !== site_url( 'wp-login.php' ) ) { 
  9. $user = get_user_by( 'email', $tokens['recipient.email'] ); 
  10.  
  11. $headers['List-Unsubscribe'] = sprintf( 
  12. '<%s>',  
  13. 'user_id' => $user->ID,  
  14. 'notification_type' => $email->get( 'type' ),  
  15. ) ) ) 
  16. ); 
  17.  
  18. return $headers;