bp_email_set_default_tokens

Add default email tokens.

Description

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

Returns (array)

Parameters (4)

0. $tokens (array)
Email tokens.
1. $property_name (string)
The property name.
2. $transform (string)
The transform.
3. $email (BP_Email)
Email being sent.

Usage

  1. if ( !function_exists( 'bp_email_set_default_tokens' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-filters.php'; 
  3.  
  4. // Email tokens. 
  5. $tokens = array(); 
  6.  
  7. // The property name. 
  8. $property_name = ''; 
  9.  
  10. // The transform. 
  11. $transform = ''; 
  12.  
  13. // Email being sent. 
  14. $email = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bp_email_set_default_tokens($tokens, $property_name, $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_tokens( $tokens, $property_name, $transform, $email ) { 
  2. $tokens['site.admin-email'] = bp_get_option( 'admin_email' ); 
  3. $tokens['site.url'] = home_url(); 
  4.  
  5. // These options are escaped with esc_html on the way into the database in sanitize_option(). 
  6. $tokens['site.description'] = wp_specialchars_decode( bp_get_option( 'blogdescription' ), ENT_QUOTES ); 
  7. $tokens['site.name'] = wp_specialchars_decode( bp_get_option( 'blogname' ), ENT_QUOTES ); 
  8.  
  9. // Default values for tokens set conditionally below. 
  10. $tokens['email.preheader'] = ''; 
  11. $tokens['recipient.email'] = ''; 
  12. $tokens['recipient.name'] = ''; 
  13. $tokens['recipient.username'] = ''; 
  14.  
  15.  
  16. // Who is the email going to? 
  17. $recipient = $email->get( 'to' ); 
  18. if ( $recipient ) { 
  19. $recipient = array_shift( $recipient ); 
  20. $user_obj = $recipient->get_user( 'search-email' ); 
  21.  
  22. $tokens['recipient.email'] = $recipient->get_address(); 
  23. $tokens['recipient.name'] = $recipient->get_name(); 
  24.  
  25. if ( ! $user_obj && $tokens['recipient.email'] ) { 
  26. $user_obj = get_user_by( 'email', $tokens['recipient.email'] ); 
  27.  
  28. if ( $user_obj ) { 
  29. $tokens['recipient.username'] = $user_obj->user_login; 
  30. if ( bp_is_active( 'settings' ) && empty( $tokens['unsubscribe'] ) ) { 
  31. $tokens['unsubscribe'] = esc_url( sprintf( 
  32. '%s%s/notifications/',  
  33. bp_core_get_user_domain( $user_obj->ID ),  
  34. ) ); 
  35.  
  36. // Set default unsubscribe link if not passed. 
  37. if ( empty( $tokens['unsubscribe'] ) ) { 
  38. $tokens['unsubscribe'] = site_url( 'wp-login.php' ); 
  39.  
  40. // Email preheader. 
  41. $post = $email->get_post_object(); 
  42. if ( $post ) { 
  43. $tokens['email.preheader'] = sanitize_text_field( get_post_meta( $post->ID, 'bp_email_preheader', true ) ); 
  44.  
  45. return $tokens;