Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/27/2016 08:23:37 PM (10 years ago)
Author:
djpaul
Message:

Emails: add post type and taxonomy, and supporting wp-admin customisations.

All of BuddyPress' emails have been moved into email posts. The change includes an installation routine, but this won't be run until the db_version number is bumped in a subsequent commit. Updates to functions using wp_mail will also follow.

Tokens are used to personalise the email content (e.g. to add a link to the recipient’s user profile). Each type of email in BuddyPress has been assigned a unique type, and these are mapped to the email post through a new "email type" taxonomy.

The change includes a new HTML email template based on work by Ted Goas and contributors from the Cerberus email templates project. Ted, thank you very much. Learn more at http://tedgoas.github.io/Cerberus/

See #6592. Props timersys, mercime, boonebgorges, hnla, DJPaul.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-filters.php

    r10472 r10474  
    10871087}
    10881088add_filter( 'bp_email_get_property', 'bp_email_add_link_color_to_template', 6, 3 );
     1089
     1090/**
     1091 * Find and render the template for Email posts (the Customizer and admin previews).
     1092 *
     1093 * Misuses the `template_include` filter which expects a string, but as we need to replace
     1094 * the `{{{content}}}` token with the post's content, we use object buffering to load the
     1095 * template, replace the token, and render it.
     1096 *
     1097 * The function returns an empty string to prevent WordPress rendering another template.
     1098 *
     1099 * @since 2.5.0
     1100 *
     1101 * @param string $template Path to template (probably single.php).
     1102 * @return string
     1103 */
     1104function bp_core_render_email_template( $template ) {
     1105    if ( get_post_type() !== bp_get_email_post_type() || ! is_single() ) {
     1106        return $template;
     1107    }
     1108
     1109    /**
     1110     * Filter template used to display Email posts.
     1111     *
     1112     * @since 2.5.0
     1113     *
     1114     * @param string $template Path to current template (probably single.php).
     1115     */
     1116    $email_template = apply_filters( 'bp_core_render_email_template',
     1117        bp_locate_template( bp_email_get_template( get_queried_object() ), false ),
     1118        $template
     1119    );
     1120
     1121    if ( ! $email_template ) {
     1122        return $template;
     1123    }
     1124
     1125    ob_start();
     1126    include( $email_template );
     1127    $template = ob_get_contents();
     1128    ob_end_clean();
     1129
     1130    echo str_replace( '{{{content}}}', nl2br( get_post()->post_content ), $template );
     1131
     1132    /*
     1133     * Link colours are applied directly in the email template before sending, so we
     1134     * need to add an extra style here to set the colour for the Customizer or preview.
     1135     */
     1136    $settings = bp_email_get_appearance_settings();
     1137    printf(
     1138        '<style>a { color: %s; }</style>',
     1139        esc_attr( $settings['highlight_color'] )
     1140    );
     1141
     1142    return '';
     1143}
     1144add_action( 'bp_template_include', 'bp_core_render_email_template', 12 );
Note: See TracChangeset for help on using the changeset viewer.