bp_get_email

Get an BP_Email object for the specified email type.

Description

(BP_Email|WP_Error) bp_get_email( (string) $email_type ); 

This function pre-populates the object with the subject, content, and template from the appropriate email post type item. It does not replace placeholder tokens in the content with real values.

Returns (BP_Email|WP_Error)

BP_Email object, or WP_Error if there was a problem.

Parameters (1)

0. $email_type (string)
Unique identifier for a particular type of email.

Usage

  1. if ( !function_exists( 'bp_get_email' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // Unique identifier for a particular type of email. 
  5. $email_type = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_get_email($email_type); 
  9.  

Defined (1)

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

/bp-core/bp-core-functions.php  
  1. function bp_get_email( $email_type ) { 
  2. $switched = false; 
  3.  
  4. // Switch to the root blog, where the email posts live. 
  5. if ( ! bp_is_root_blog() ) { 
  6. $switched = true; 
  7.  
  8. $args = array( 
  9. 'no_found_rows' => true,  
  10. 'numberposts' => 1,  
  11. 'post_status' => 'publish',  
  12. 'post_type' => bp_get_email_post_type(),  
  13. 'suppress_filters' => false,  
  14.  
  15. 'tax_query' => array( 
  16. array( 
  17. 'field' => 'slug',  
  18. 'taxonomy' => bp_get_email_tax_type(),  
  19. 'terms' => $email_type,  
  20. ),  
  21. ); 
  22.  
  23. /** 
  24. * Filters arguments used to find an email post type object. 
  25. * @since 2.5.0 
  26. * @param array $args Arguments for get_posts() used to fetch a post object. 
  27. * @param string $email_type Unique identifier for a particular type of email. 
  28. */ 
  29. $args = apply_filters( 'bp_get_email_args', $args, $email_type ); 
  30. $post = get_posts( $args ); 
  31. if ( ! $post ) { 
  32. if ( $switched ) { 
  33.  
  34. return new WP_Error( 'missing_email', __FUNCTION__, array( $email_type, $args ) ); 
  35.  
  36. /** 
  37. * Filters arguments used to create the BP_Email object. 
  38. * @since 2.5.0 
  39. * @param WP_Post $post Post object containing the contents of the email. 
  40. * @param string $email_type Unique identifier for a particular type of email. 
  41. * @param array $args Arguments used with get_posts() to fetch a post object. 
  42. * @param WP_Post $post All posts retrieved by get_posts( $args ). May only contain $post. 
  43. */ 
  44. $post = apply_filters( 'bp_get_email_post', $post[0], $email_type, $args, $post ); 
  45. $email = new BP_Email( $email_type ); 
  46.  
  47.  
  48. /** 
  49. * Set some email properties for convenience. 
  50. */ 
  51.  
  52. // Post object (sets subject, content, template). 
  53. $email->set_post_object( $post ); 
  54.  
  55. /** 
  56. * Filters the BP_Email object returned by bp_get_email(). 
  57. * @since 2.5.0 
  58. * @param BP_Email $email An object representing a single email, ready for mailing. 
  59. * @param string $email_type Unique identifier for a particular type of email. 
  60. * @param array $args Arguments used with get_posts() to fetch a post object. 
  61. * @param WP_Post $post All posts retrieved by get_posts( $args ). May only contain $post. 
  62. */ 
  63. $retval = apply_filters( 'bp_get_email', $email, $email_type, $args, $post ); 
  64.  
  65. if ( $switched ) { 
  66.  
  67. return $retval;