bp_core_render_email_template( string $template )

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

Description

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.

Parameters

$template

(Required) Path to template (probably single.php).

Return

(string)

Source

File: bp-core/bp-core-filters.php

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
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 BuddyPress 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__( 'BuddyBoss Emails', 'buddyboss' ) . '</title>', $template );
    echo str_replace( '{{{content}}}', wpautop( 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 '';
}

Changelog

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.