bp_core_render_email_template

Find and render the template for Email posts (the Customizer and admin previews).

Description

(string) bp_core_render_email_template( (string) $template ); 

Misuses the template_include filter which expects a string, but as we need to replace the }} token with the post's content, we use object buffering to load the template, replace the token, and render it.

The function returns an empty string to prevent WordPress rendering another template.

Returns (string)

Parameters (1)

0. $template (string)
Path to template (probably single.php).

Usage

  1. if ( !function_exists( 'bp_core_render_email_template' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-filters.php'; 
  3.  
  4. // Path to template (probably single.php). 
  5. $template = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_render_email_template($template); 
  9.  

Defined (1)

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

/bp-core/bp-core-filters.php  
  1. function bp_core_render_email_template( $template ) { 
  2. if ( get_post_type() !== bp_get_email_post_type() || ! is_single() ) { 
  3. return $template; 
  4.  
  5. /** 
  6. * Filter template used to display Email posts. 
  7. * @since 2.5.0 
  8. * @param string $template Path to current template (probably single.php). 
  9. */ 
  10. bp_locate_template( bp_email_get_template( get_queried_object() ), false ),  
  11. $template 
  12. ); 
  13.  
  14. if ( ! $email_template ) { 
  15. return $template; 
  16.  
  17. ob_start(); 
  18. include( $email_template ); 
  19. $template = ob_get_contents(); 
  20. ob_end_clean(); 
  21.  
  22. // Make sure we add a <title> tag so WP Customizer picks it up. 
  23. $template = str_replace( '<head>', '<head><title>' . esc_html_x( 'BuddyPress Emails', 'screen heading', buddypress ) . '</title>', $template ); 
  24. echo str_replace( '{{{content}}}', nl2br( get_post()->post_content ), $template ); 
  25.  
  26. /** 
  27. * Link colours are applied directly in the email template before sending, so we 
  28. * need to add an extra style here to set the colour for the Customizer or preview. 
  29. */ 
  30. printf( 
  31. '<style>a { color: %s; }</style>',  
  32. esc_attr( $settings['highlight_color'] ) 
  33. ); 
  34.  
  35. return '';