/**
  * Apply inline styles to dynamic content.
  *
  * @param string|null $content
  * @return string
  */
 public function style_inline($content)
 {
     // Make sure we only inline CSS for HTML emails.
     if (in_array($this->get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
         // Get CSS styles
         ob_start();
         bp_email_get_template('email-styles.php');
         $css = apply_filters('welcome_buddy_styles', ob_get_clean());
         // Apply CSS styles inline for picky email clients.
         $emogrifier = new Emogrifier($content, $css);
         $content = $emogrifier->emogrify();
     }
     return $content;
 }
 /**
  * Set the Post object containing the email content template.
  *
  * Also sets the email's subject, content, and template from the Post, for convenience.
  *
  * @since 2.5.0
  *
  * @param WP_Post $post
  * @return BP_Email
  */
 public function set_post_object(WP_Post $post)
 {
     /**
      * Filters the new value of the email's "post object" property.
      *
      * @since 2.5.0
      *
      * @param WP_Post $post A Post.
      * @param BP_Email $this Current instance of the email type class.
      */
     $this->post_object = apply_filters('bp_email_set_post_object', $post, $this);
     if (is_a($this->post_object, 'WP_Post')) {
         $this->set_subject($this->post_object->post_title)->set_content_html($this->post_object->post_content)->set_content_plaintext($this->post_object->post_excerpt);
         ob_start();
         // Load the template.
         add_filter('bp_locate_template_and_load', '__return_true');
         bp_locate_template(bp_email_get_template($this->post_object), true, false);
         remove_filter('bp_locate_template_and_load', '__return_true');
         $this->set_template(ob_get_contents());
         ob_end_clean();
     }
     return $this;
 }
 /**
  * Get the email footer.
  *
  * @since  1.0.0
  * @access public
  */
 public function email_footer()
 {
     bp_email_get_template('email-footer.php');
 }
 /**
  * Prepair the content for a plain email.
  *
  * @access public
  * @return string
  */
 public function get_content_plain()
 {
     ob_start();
     bp_email_get_template($this->template_plain, array('email_heading' => $this->get_heading(), 'user_name' => $this->user_name, 'user_login' => $this->user_login, 'user_pass' => $this->user_pass, 'blogname' => $this->get_blogname(), 'sent_to_admin' => false, 'plain_text' => true));
     return ob_get_clean();
 }
/**
 * Find and render the template for Email posts (the Customizer and admin previews).
 *
 * Misuses the `template_include` filter which expects a string, but as we need to replace
 * the `{{{content}}}` 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.
 *
 * @since 2.5.0
 *
 * @param string $template Path to template (probably single.php).
 * @return string
 */
function bp_core_render_email_template($template)
{
    if (get_post_type() !== bp_get_email_post_type() || !is_single()) {
        return $template;
    }
    /**
     * Filter template used to display Email posts.
     *
     * @since 2.5.0
     *
     * @param string $template Path to current template (probably single.php).
     */
    $email_template = apply_filters('bp_core_render_email_template', bp_locate_template(bp_email_get_template(get_queried_object()), false), $template);
    if (!$email_template) {
        return $template;
    }
    ob_start();
    include $email_template;
    $template = ob_get_contents();
    ob_end_clean();
    // Make sure we add a <title> tag so WP Customizer picks it up.
    $template = str_replace('<head>', '<head><title>' . esc_html_x('BuddyPress Emails', 'screen heading', 'buddypress') . '</title>', $template);
    echo str_replace('{{{content}}}', nl2br(get_post()->post_content), $template);
    /*
     * Link colours are applied directly in the email template before sending, so we
     * need to add an extra style here to set the colour for the Customizer or preview.
     */
    $settings = bp_email_get_appearance_settings();
    printf('<style>a { color: %s; }</style>', esc_attr($settings['highlight_color']));
    return '';
}