bp_get_email( string $email_type )
Get an BP_Email object for the specified email type.
Description
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.
Parameters
- $email_type
-
(Required) Unique identifier for a particular type of email.
Return
(BP_Email|WP_Error) BP_Email object, or WP_Error if there was a problem.
Source
File: bp-core/bp-core-functions.php
3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 | function bp_get_email( $email_type ) { $switched = false; // Switch to the root blog, where the email posts live. if ( ! bp_is_root_blog() ) { switch_to_blog( bp_get_root_blog_id() ); $switched = true; } $args = array ( 'no_found_rows' => true, 'numberposts' => 1, 'post_status' => 'publish' , 'post_type' => bp_get_email_post_type(), 'suppress_filters' => false, 'tax_query' => array ( array ( 'field' => 'slug' , 'taxonomy' => bp_get_email_tax_type(), 'terms' => $email_type , ) ), ); /** * Filters arguments used to find an email post type object. * * @since BuddyPress 2.5.0 * * @param array $args Arguments for get_posts() used to fetch a post object. * @param string $email_type Unique identifier for a particular type of email. */ $args = apply_filters( 'bp_get_email_args' , $args , $email_type ); $post = get_posts( $args ); if ( ! $post ) { if ( $switched ) { restore_current_blog(); } return new WP_Error( 'missing_email' , __FUNCTION__ , array ( $email_type , $args ) ); } /** * Filters arguments used to create the BP_Email object. * * @since BuddyPress 2.5.0 * * @param WP_Post $post Post object containing the contents of the email. * @param string $email_type Unique identifier for a particular type of email. * @param array $args Arguments used with get_posts() to fetch a post object. * @param WP_Post $post All posts retrieved by get_posts( $args ). May only contain $post. */ $post = apply_filters( 'bp_get_email_post' , $post [0], $email_type , $args , $post ); $email = new BP_Email( $email_type ); /* * Set some email properties for convenience. */ // Post object (sets subject, content, template). $email ->set_post_object( $post ); /** * Filters the BP_Email object returned by bp_get_email(). * * @since BuddyPress 2.5.0 * * @param BP_Email $email An object representing a single email, ready for mailing. * @param string $email_type Unique identifier for a particular type of email. * @param array $args Arguments used with get_posts() to fetch a post object. * @param WP_Post $post All posts retrieved by get_posts( $args ). May only contain $post. */ $retval = apply_filters( 'bp_get_email' , $email , $email_type , $args , $post ); if ( $switched ) { restore_current_blog(); } return $retval ; } |
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.