Skip to:
Content

BuddyPress.org

Changeset 10474


Ignore:
Timestamp:
01/27/2016 08:23:37 PM (4 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.

Location:
trunk/src
Files:
5 added
9 edited

Legend:

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

    r10417 r10474  
    812812
    813813/**
     814 * In admin emails list, for non-en_US locales, add notice explaining how to reinstall emails.
     815 *
     816 * If BuddyPress installs before its translations are in place, tell people how to reinstall
     817 * the emails so they have their contents in their site's language.
     818 *
     819 * @since 2.5.0
     820 */
     821function bp_admin_email_maybe_add_translation_notice() {
     822    if ( get_current_screen()->post_type !== bp_get_email_post_type() || get_locale() === 'en_US' ) {
     823        return;
     824    }
     825
     826    // If user can't access BP Tools, there's no point showing the message.
     827    if ( ! current_user_can( buddypress()->admin->capability ) ) {
     828        return;
     829    }
     830
     831    bp_core_add_admin_notice(
     832        sprintf(
     833            __( 'Are your emails in the wrong language? Go to <a href="%s">BuddyPress Tools and run the "reinstall emails"</a> tool.', 'buddypress' ),
     834            bp_get_admin_url( 'tools.php?page=bp-tools' )
     835        ),
     836        'updated'
     837    );
     838}
     839add_action( 'admin_head-edit.php', 'bp_admin_email_maybe_add_translation_notice' );
     840
     841/**
     842 * In emails editor, add notice linking to token documentation on Codex.
     843 *
     844 * @since 2.5.0
     845 */
     846function bp_admin_email_add_codex_notice() {
     847    if ( get_current_screen()->post_type !== bp_get_email_post_type() ) {
     848        return;
     849    }
     850
     851    bp_core_add_admin_notice(
     852        sprintf(
     853            __( 'Phrases wrapped in braces <code>{{ }}</code> are email tokens. <a href="%s">Learn about tokens on the BuddyPress Codex</a>.', 'buddypress' ),
     854            esc_url( 'https://codex.buddypress.org/emails/email-tokens/' )
     855        ),
     856        'error'
     857    );
     858}
     859add_action( 'admin_head-post.php', 'bp_admin_email_add_codex_notice' );
     860
     861/**
     862 * Display metabox for email taxonomy type.
     863 *
     864 * Shows the term description in a list, rather than the term name itself.
     865 *
     866 * @since 2.5.0
     867 *
     868 * @param WP_Post $post Post object.
     869 * @param array   $box {
     870 *     Tags meta box arguments.
     871 *
     872 *     @type string   $id       Meta box ID.
     873 *     @type string   $title    Meta box title.
     874 *     @type callable $callback Meta box display callback.
     875 * }
     876 */
     877function bp_email_tax_type_metabox( $post, $box ) {
     878    $r = array(
     879        'taxonomy' => bp_get_email_tax_type()
     880    );
     881
     882    $tax_name = esc_attr( $r['taxonomy'] );
     883    $taxonomy = get_taxonomy( $r['taxonomy'] );
     884    ?>
     885    <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
     886        <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
     887            <?php
     888            $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
     889            echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
     890            ?>
     891            <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
     892                <?php wp_terms_checklist( $post->ID, array( 'taxonomy' => $tax_name, 'walker' => new BP_Walker_Category_Checklist ) ); ?>
     893            </ul>
     894        </div>
     895
     896        <p><?php esc_html_e( 'Choose when this email will be sent.', 'buddypress' ); ?></p>
     897    </div>
     898    <?php
     899}
     900
     901/**
    814902 * Restrict various items from view if editing a BuddyPress menu.
    815903 *
  • trunk/src/bp-core/admin/bp-core-admin-schema.php

    r10417 r10474  
    527527    $wpdb->query( "ALTER TABLE {$wpdb->signups} DROP INDEX domain" );
    528528}
     529
     530/**
     531 * Add default emails.
     532 *
     533 * @since 2.5.0
     534 */
     535function bp_core_install_emails() {
     536    $defaults = array(
     537        'post_status' => 'publish',
     538        'post_type'   => bp_get_email_post_type(),
     539    );
     540
     541    $emails = array(
     542        'activity-comment' => array(
     543            /* translators: do not remove {} brackets or translate its contents. */
     544            'post_title'   => __( '[{{{site.name}}}] {{poster.name}} replied to one of your updates', 'buddypress' ),
     545            /* translators: do not remove {} brackets or translate its contents. */
     546            'post_content' => __( "{{poster.name}} replied to one of your updates:\n\n<blockquote>&quot;{{usermessage}}&quot;</blockquote>\n\n<a href=\"{{{thread.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress' ),
     547            /* translators: do not remove {} brackets or translate its contents. */
     548            'post_excerpt' => __( "{{poster.name}} replied to one of your updates:\n\n\"{{usermessage}}\"\n\nGo to the discussion to reply or catch up on the conversation: {{{thread.url}}}", 'buddypress' ),
     549        ),
     550        'activity-comment-author' => array(
     551            /* translators: do not remove {} brackets or translate its contents. */
     552            'post_title'   => __( '[{{{site.name}}}] {{poster.name}} replied to one of your comments', 'buddypress' ),
     553            /* translators: do not remove {} brackets or translate its contents. */
     554            'post_content' => __( "{{poster.name}} replied to one of your comments:\n\n<blockquote>&quot;{{usermessage}}&quot;</blockquote>\n\n<a href=\"{{{thread.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress' ),
     555            /* translators: do not remove {} brackets or translate its contents. */
     556            'post_excerpt' => __( "{{poster.name}} replied to one of your comments:\n\n\"{{usermessage}}\"\n\nGo to the discussion to reply or catch up on the conversation: {{{thread.url}}}", 'buddypress' ),
     557        ),
     558        'activity-at-message' => array(
     559            /* translators: do not remove {} brackets or translate its contents. */
     560            'post_title'   => __( '[{{{site.name}}}] {{poster.name}} mentioned you in a status update', 'buddypress' ),
     561            /* translators: do not remove {} brackets or translate its contents. */
     562            'post_content' => __( "{{poster.name}} mentioned you in a status update:\n\n<blockquote>&quot;{{usermessage}}&quot;</blockquote>\n\n<a href=\"{{{mentioned.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress' ),
     563            /* translators: do not remove {} brackets or translate its contents. */
     564            'post_excerpt' => __( "{{poster.name}} mentioned you in a status update:\n\n\"{{usermessage}}\"\n\nGo to the discussion to reply or catch up on the conversation: {{{mentioned.url}}}", 'buddypress' ),
     565        ),
     566        'groups-at-message' => array(
     567            /* translators: do not remove {} brackets or translate its contents. */
     568            'post_title'   => __( '[{{{site.name}}}] {{poster.name}} mentioned you in an update', 'buddypress' ),
     569            /* translators: do not remove {} brackets or translate its contents. */
     570            'post_content' => __( "{{poster.name}} mentioned you in the group \"{{group.name}}\":\n\n<blockquote>&quot;{{usermessage}}&quot;</blockquote>\n\n<a href=\"{{{group-mentioned.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress' ),
     571            /* translators: do not remove {} brackets or translate its contents. */
     572            'post_excerpt' => __( "{{poster.name}} mentioned you in the group \"{{group.name}}\":\n\n\"{{usermessage}}\"\n\nGo to the discussion to reply or catch up on the conversation: {{{group-mentioned.url}}}", 'buddypress' ),
     573        ),
     574        'core-user-registration' => array(
     575            /* translators: do not remove {} brackets or translate its contents. */
     576            'post_title'   => __( '[{{{site.name}}}] Activate your account', 'buddypress' ),
     577            /* translators: do not remove {} brackets or translate its contents. */
     578            'post_content' => __( "Thanks for registering!\n\nTo complete the activation of your account, go to the following link: <a href=\"{{{activate.url}}}\">{{{activate.url}}}</a>", 'buddypress' ),
     579            /* translators: do not remove {} brackets or translate its contents. */
     580            'post_excerpt' => __( "Thanks for registering!\n\nTo complete the activation of your account, go to the following link: {{{activate.url}}}", 'buddypress' ),
     581        ),
     582        'core-user-registration-with-blog' => array(
     583            /* translators: do not remove {} brackets or translate its contents. */
     584            'post_title'   => __( '[{{{site.name}}}] Activate {{{user-site.url}}}', 'buddypress' ),
     585            /* translators: do not remove {} brackets or translate its contents. */
     586            'post_content' => __( "Thanks for registering!\n\nTo complete the activation of your account and site, go to the following link: <a href=\"{{{activate-site.url}}}\">{{{activate-site.url}}}</a>.\n\nAfter you activate, you can visit your site at <a href=\"{{{user-site.url}}}\">{{{user-site.url}}}</a>.", 'buddypress' ),
     587            /* translators: do not remove {} brackets or translate its contents. */
     588            'post_excerpt' => __( "Thanks for registering!\n\nTo complete the activation of your account and site, go to the following link: {{{activate-site.url}}}\n\nAfter you activate, you can visit your site at {{{user-site.url}}}.", 'buddypress' ),
     589        ),
     590        'friends-request' => array(
     591            /* translators: do not remove {} brackets or translate its contents. */
     592            'post_title'   => __( '[{{{site.name}}}] New friendship request from {{initiator.name}}', 'buddypress' ),
     593            /* translators: do not remove {} brackets or translate its contents. */
     594            'post_content' => __( "<a href=\"{{{initiator.url}}}\">{{initiator.name}}</a> wants to add you as a friend.\n\nTo accept this request and manage all of your pending requests, visit: <a href=\"{{{friend-requests.url}}}\">{{{friend-requests.url}}}</a>", 'buddypress' ),
     595            /* translators: do not remove {} brackets or translate its contents. */
     596            'post_excerpt' => __( "{{initiator.name}} wants to add you as a friend.\n\nTo accept this request and manage all of your pending requests, visit: {{{friend-requests.url}}}\n\nTo view {{initiator.name}}'s profile, visit: {{{initiator.url}}}", 'buddypress' ),
     597        ),
     598        'friends-request-accepted' => array(
     599            /* translators: do not remove {} brackets or translate its contents. */
     600            'post_title'   => __( '[{{{site.name}}}] {{friend.name}} accepted your friendship request', 'buddypress' ),
     601            /* translators: do not remove {} brackets or translate its contents. */
     602            'post_content' => __( "<a href=\"{{{friendship.url}}}\">{{friend.name}}</a> accepted your friend request.", 'buddypress' ),
     603            /* translators: do not remove {} brackets or translate its contents. */
     604            'post_excerpt' => __( "{{friend.name}} accepted your friend request.\n\nTo learn more about them, visit their profile: {{{friendship.url}}}", 'buddypress' ),
     605        ),
     606        'groups-details-updated' => array(
     607            /* translators: do not remove {} brackets or translate its contents. */
     608            'post_title'   => __( '[{{{site.name}}}] Group details updated', 'buddypress' ),
     609            /* translators: do not remove {} brackets or translate its contents. */
     610            'post_content' => __( "Group details for the group &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot; were updated:\n<blockquote>{{changed_text}}</blockquote>", 'buddypress' ),
     611            /* translators: do not remove {} brackets or translate its contents. */
     612            'post_excerpt' => __( "Group details for the group &quot;{{group.name}}&quot; were updated:\n\n{{changed_text}}\n\nTo view the group, visit: {{{group.url}}}", 'buddypress' ),
     613        ),
     614        'groups-invitation' => array(
     615            /* translators: do not remove {} brackets or translate its contents. */
     616            'post_title'   => __( '[{{{site.name}}}] You have an invitation to the group: "{{group.name}}"', 'buddypress' ),
     617            /* translators: do not remove {} brackets or translate its contents. */
     618            'post_content' => __( "<a href=\"{{{inviter.url}}}\">{{inviter.name}}</a> has invited you to join the group: &quot;{{group.name}}&quot;.\n<a href=\"{{{invites.url}}}\">Go here to accept your invitation</a> or <a href=\"{{{group.url}}}\">visit the group</a> to learn more.", 'buddypress' ),
     619            /* translators: do not remove {} brackets or translate its contents. */
     620            'post_excerpt' => __( "{{inviter.name}} has invited you to join the group: &quot;{{group.name}}&quot;.\n\nTo accept your invitation, visit: {{{invites.url}}}\n\nTo learn more about the group, visit {{{group.url}}}.\nTo view {{inviter.name}}'s profile, visit: {{{inviter.url}}}", 'buddypress' ),
     621        ),
     622        'groups-member-promoted' => array(
     623            /* translators: do not remove {} brackets or translate its contents. */
     624            'post_title'   => __( '[{{{site.name}}}] You have been promoted in the group: "{{group.name}}"', 'buddypress' ),
     625            /* translators: do not remove {} brackets or translate its contents. */
     626            'post_content' => __( "You have been promoted to <b>{{promoted_to}}</b> in the group &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot;.", 'buddypress' ),
     627            /* translators: do not remove {} brackets or translate its contents. */
     628            'post_excerpt' => __( "You have been promoted to {{promoted_to}} in the group: &quot;{{group.name}}&quot;.\n\nTo visit the group, go to: {{{group.url}}}", 'buddypress' ),
     629        ),
     630        'groups-membership-request' => array(
     631            /* translators: do not remove {} brackets or translate its contents. */
     632            'post_title'   => __( '[{{{site.name}}}] Membership request for group: {{group.name}}', 'buddypress' ),
     633            /* translators: do not remove {} brackets or translate its contents. */
     634            'post_content' => __( "<a href=\"{{{profile.url}}}\">{{requesting-user.name}}</a> wants to join the group &quot;{{group.name}}&quot;. As you are an administrator of this group, you must either accept or reject the membership request.\n\n<a href=\"{{{group-requests.url}}}\">Go here to manage this</a> and all other pending requests.", 'buddypress' ),
     635            /* translators: do not remove {} brackets or translate its contents. */
     636            'post_excerpt' => __( "{{requesting-user.name}} wants to join the group &quot;{{group.name}}&quot;. As you are the administrator of this group, you must either accept or reject the membership request.\n\nTo manage this and all other pending requests, visit: {{{group-requests.url}}}\n\nTo view {{requesting-user.name}}'s profile, visit: {{{profile.url}}}", 'buddypress' ),
     637        ),
     638        'messages-unread' => array(
     639            /* translators: do not remove {} brackets or translate its contents. */
     640            'post_title'   => __( '[{{{site.name}}}] New message from {{sender.name}}', 'buddypress' ),
     641            /* translators: do not remove {} brackets or translate its contents. */
     642            'post_content' => __( "{{sender.name}} sent you a new message: &quot;{{usersubject}}&quot;\n\n<blockquote>&quot;{{usermessage}}&quot;</blockquote>\n\n<a href=\"{{{message.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress' ),
     643            /* translators: do not remove {} brackets or translate its contents. */
     644            'post_excerpt' => __( "{{sender.name}} sent you a new message: &quot;{{usersubject}}&quot;\n\n&quot;{{usermessage}}&quot;\n\nGo to the discussion to reply or catch up on the conversation: {{{message.url}}}", 'buddypress' ),
     645        ),
     646        'settings-verify-email-change' => array(
     647            /* translators: do not remove {} brackets or translate its contents. */
     648            'post_title'   => __( '[{{{site.name}}}] Verify your new email address', 'buddypress' ),
     649            /* translators: do not remove {} brackets or translate its contents. */
     650            'post_content' => __( "You recently changed the email address associated with your account on {{site.name}}. If this is correct, <a href=\"{{{verify.url}}}\">go here to confirm the change</a>.\n\nOtherwise, you can safely ignore and delete this email if you have changed your mind, or if you think you have received this email in error.", 'buddypress' ),
     651            /* translators: do not remove {} brackets or translate its contents. */
     652            'post_excerpt' => __( "You recently changed the email address associated with your account on {{site.name}}. If this is correct, go to the following link to confirm the change: {{{verify.url}}}\n\nOtherwise, you can safely ignore and delete this email if you have changed your mind, or if you think you have received this email in error.", 'buddypress' ),
     653        ),
     654        'groups-membership-request-accepted' => array(
     655            /* translators: do not remove {} brackets or translate its contents. */
     656            'post_title'   => __( '[{{{site.name}}}] Membership request for group "{{group.name}}" accepted', 'buddypress' ),
     657            /* translators: do not remove {} brackets or translate its contents. */
     658            'post_content' => __( "Your membership request for the group &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot; has been accepted.", 'buddypress' ),
     659            /* translators: do not remove {} brackets or translate its contents. */
     660            'post_excerpt' => __( "Your membership request for the group &quot;{{group.name}}&quot; has been accepted.\n\nTo view the group, visit: {{{group.url}}}", 'buddypress' ),
     661        ),
     662        'groups-membership-request-rejected' => array(
     663            /* translators: do not remove {} brackets or translate its contents. */
     664            'post_title'   => __( '[{{{site.name}}}] Membership request for group "{{group.name}}" rejected', 'buddypress' ),
     665            /* translators: do not remove {} brackets or translate its contents. */
     666            'post_content' => __( "Your membership request for the group &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot; has been rejected.", 'buddypress' ),
     667            /* translators: do not remove {} brackets or translate its contents. */
     668            'post_excerpt' => __( "Your membership request for the group &quot;{{group.name}}&quot; has been rejected.\n\nTo request membership again, visit: {{{group.url}}}", 'buddypress' ),
     669        ),
     670    );
     671
     672    $descriptions = array(
     673        'activity-comment'                   => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ),
     674        'activity-comment-author'            => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ),
     675        'activity-at-message'                => __( 'Recipient was mentioned in an activity update.', 'buddypress' ),
     676        'groups-at-message'                  => __( 'Recipient was mentioned in a group activity update.', 'buddypress' ),
     677        'core-user-registration'             => __( 'Recipient has registered for an account.', 'buddypress' ),
     678        'core-user-registration-with-blog'   => __( 'Recipient has registered for an account and site.', 'buddypress' ),
     679        'friends-request'                    => __( 'A member has sent a friend request to the recipient.', 'buddypress' ),
     680        'friends-request-accepted'           => __( 'Recipient has had a friend request accepted by a member.', 'buddypress' ),
     681        'groups-details-updated'             => __( "A group's details were updated.", 'buddypress' ),
     682        'groups-invitation'                  => __( 'A member has sent a group invitation to the recipient.', 'buddypress' ),
     683        'groups-member-promoted'             => __( "Recipient's status within a group have changed.", 'buddypress' ),
     684        'groups-membership-request'          => __( 'A member has requested permission to join a group.', 'buddypress' ),
     685        'messages-unread'                    => __( 'Recipient has received a private message.', 'buddypress' ),
     686        'settings-verify-email-change'       => __( 'Recipient has changed their email address.', 'buddypress' ),
     687        'groups-membership-request-accepted' => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ),
     688        'groups-membership-request-rejected' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
     689    );
     690
     691    // Add these emails to the database.
     692    foreach ( $emails as $id => $email ) {
     693        $post_id = wp_insert_post( bp_parse_args( $email, $defaults, 'install_email_' . $id ) );
     694        if ( ! $post_id ) {
     695            continue;
     696        }
     697
     698        $term_ids = wp_set_post_terms( $post_id, $id, bp_get_email_tax_type() );
     699        foreach ( $term_ids as $term_id ) {
     700            wp_update_term( (int) $term_id, bp_get_email_tax_type(), array(
     701                'description' => $descriptions[ $id ],
     702            ) );
     703        }
     704    }
     705
     706    /**
     707     * Fires after BuddyPress adds the posts for its emails.
     708     *
     709     * @since 2.5.0
     710     */
     711    do_action( 'bp_core_install_emails' );
     712}
  • trunk/src/bp-core/bp-core-admin.php

    r10417 r10474  
    117117     */
    118118    private function includes() {
     119        require( $this->admin_dir . 'bp-core-admin-classes.php'    );
    119120        require( $this->admin_dir . 'bp-core-admin-actions.php'    );
    120121        require( $this->admin_dir . 'bp-core-admin-settings.php'   );
     
    175176        add_filter( 'ms_user_row_actions', 'bp_core_admin_user_row_actions', 10, 2 );
    176177        add_filter( 'user_row_actions',    'bp_core_admin_user_row_actions', 10, 2 );
     178
     179        // Emails
     180        add_filter( 'bp_admin_menu_order', array( $this, 'emails_admin_menu_order' ), 20 );
    177181    }
    178182
     
    296300        );
    297301
    298         // Fudge the highlighted subnav item when on a BuddyPress admin page.
     302        $hooks[] = add_theme_page(
     303            _x( 'Emails', 'screen heading', 'buddypress' ),
     304            _x( 'Emails', 'screen heading', 'buddypress' ),
     305            $this->capability,
     306            'bp-emails-customizer-redirect',
     307            'bp_email_redirect_to_customizer'
     308        );
     309
    299310        foreach( $hooks as $hook ) {
    300311            add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' );
     
    768779                <a href="https://bbpress.org">bbPress</a>,
    769780                <a href="https://github.com/ichord/Caret.js">Caret.js</a>,
     781                <a href="http://tedgoas.github.io/Cerberus/">Cerberus</a>,
    770782                <a href="https://github.com/carhartl/jquery-cookie">jquery.cookie</a>,
    771783                <a href="https://www.mediawiki.org/wiki/MediaWiki">MediaWiki</a>,
     
    874886        // Done!
    875887        return $display;
     888    }
     889
     890    /**
     891     * Add Emails menu item to custom menus array.
     892     *
     893     * Several BuddyPress components have top-level menu items in the Dashboard,
     894     * which all appear together in the middle of the Dashboard menu. This function
     895     * adds the Emails screen to the array of these menu items.
     896     *
     897     * @since 2.4.0
     898     *
     899     * @param array $custom_menus The list of top-level BP menu items.
     900     * @return array $custom_menus List of top-level BP menu items, with Emails added.
     901     */
     902    public function emails_admin_menu_order( $custom_menus = array() ) {
     903        array_push( $custom_menus, 'edit.php?post_type=' . bp_get_email_post_type() );
     904        return $custom_menus;
    876905    }
    877906
  • 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 );
  • trunk/src/bp-core/bp-core-functions.php

    r10471 r10474  
    25932593}
    25942594
     2595
     2596/** Post Types *****************************************************************/
     2597
     2598/**
     2599 * Output the name of the email post type.
     2600 *
     2601 * @since 2.5.0
     2602 */
     2603function bp_email_post_type() {
     2604    echo bp_get_email_post_type();
     2605}
     2606    /**
     2607     * Returns the name of the email post type.
     2608     *
     2609     * @since 2.5.0
     2610     *
     2611     * @return string The name of the email post type.
     2612     */
     2613    function bp_get_email_post_type() {
     2614
     2615        /**
     2616         * Filters the name of the email post type.
     2617         *
     2618         * @since 2.5.0
     2619         *
     2620         * @param string $post_type Email post type name.
     2621         */
     2622        return apply_filters( 'bp_get_email_post_type', buddypress()->email_post_type );
     2623    }
     2624
     2625/**
     2626 * Return labels used by the email post type.
     2627 *
     2628 * @since 2.5.0
     2629 *
     2630 * @return array
     2631 */
     2632function bp_get_email_post_type_labels() {
     2633
     2634    /**
     2635     * Filters email post type labels.
     2636     *
     2637     * @since 2.5.0
     2638     *
     2639     * @param string[] $labels Associative array (name => label).
     2640     */
     2641    return apply_filters( 'bp_get_email_post_type_labels', array(
     2642        'add_new'               => _x( 'Add New', 'email post type label', 'buddypress' ),
     2643        'add_new_item'          => _x( 'Add a New Email', 'email post type label', 'buddypress' ),
     2644        'all_items'             => _x( 'All Emails', 'email post type label', 'buddypress' ),
     2645        'edit_item'             => _x( 'Edit Email', 'email post type label', 'buddypress' ),
     2646        'filter_items_list'     => _x( 'Filter email list', 'email post type label', 'buddypress' ),
     2647        'items_list'            => _x( 'Email list', 'email post type label', 'buddypress' ),
     2648        'items_list_navigation' => _x( 'Email list navigation', 'email post type label', 'buddypress' ),
     2649        'name'                  => _x( 'Emails', 'email post type name', 'buddypress' ),
     2650        'new_item'              => _x( 'New Email', 'email post type label', 'buddypress' ),
     2651        'not_found'             => _x( 'No emails found', 'email post type label', 'buddypress' ),
     2652        'not_found_in_trash'    => _x( 'No emails found in Trash', 'email post type label', 'buddypress' ),
     2653        'search_items'          => _x( 'Search Emails', 'email post type label', 'buddypress' ),
     2654        'singular_name'         => _x( 'Email', 'email post type singular name', 'buddypress' ),
     2655        'uploaded_to_this_item' => _x( 'Uploaded to this email', 'email post type label', 'buddypress' ),
     2656        'view_item'             => _x( 'View Email', 'email post type label', 'buddypress' ),
     2657    ) );
     2658}
     2659
     2660/**
     2661 * Return array of features that the email post type supports.
     2662 *
     2663 * @since 2.5.0
     2664 *
     2665 * @return array
     2666 */
     2667function bp_get_email_post_type_supports() {
     2668
     2669    /**
     2670     * Filters the features that the email post type supports.
     2671     *
     2672     * @since 2.5.0
     2673     *
     2674     * @param string[] $features Supported features.
     2675     */
     2676    return apply_filters( 'bp_get_email_post_type_supports', array(
     2677        'custom-fields',
     2678        'editor',
     2679        'excerpt',
     2680        'revisions',
     2681        'title',
     2682    ) );
     2683}
     2684
     2685
     2686/** Taxonomies *****************************************************************/
     2687
     2688/**
     2689 * Output the name of the email type taxonomy.
     2690 *
     2691 * @since 2.5.0
     2692 */
     2693function bp_email_tax_type() {
     2694    echo bp_get_email_tax_type();
     2695}
     2696    /**
     2697     * Return the name of the email type taxonomy.
     2698     *
     2699     * @since 2.5.0
     2700     *
     2701     * @return string The unique email taxonomy type ID.
     2702     */
     2703    function bp_get_email_tax_type() {
     2704
     2705        /**
     2706         * Filters the name of the email type taxonomy.
     2707         *
     2708         * @since 2.5.0
     2709         *
     2710         * @param string $taxonomy Email type taxonomy name.
     2711         */
     2712        return apply_filters( 'bp_get_email_tax_type', buddypress()->email_taxonomy_type );
     2713    }
     2714
     2715/**
     2716 * Return labels used by the email type taxonomy.
     2717 *
     2718 * @since 2.5.0
     2719 *
     2720 * @return string[]
     2721 */
     2722function bp_get_email_tax_type_labels() {
     2723
     2724    /**
     2725     * Filters email type taxonomy labels.
     2726     *
     2727     * @since 2.5.0
     2728     *
     2729     * @param string[] $labels Associative array (name => label).
     2730     */
     2731    return apply_filters( 'bp_get_email_tax_type_labels', array(
     2732        'add_new_item'          => _x( 'New Email Situation', 'email type taxonomy label', 'buddypress' ),
     2733        'all_items'             => _x( 'All Email Situations', 'email type taxonomy label', 'buddypress' ),
     2734        'edit_item'             => _x( 'Edit Email Situations', 'email type taxonomy label', 'buddypress' ),
     2735        'items_list'            => _x( 'Email list', 'email type taxonomy label', 'buddypress' ),
     2736        'items_list_navigation' => _x( 'Email list navigation', 'email type taxonomy label', 'buddypress' ),
     2737        'menu_name'             => _x( 'Situations', 'email type taxonomy label', 'buddypress' ),
     2738        'name'                  => _x( 'Situation', 'email type taxonomy name', 'buddypress' ),
     2739        'new_item_name'         => _x( 'New email situation name', 'email type taxonomy label', 'buddypress' ),
     2740        'not_found'             => _x( 'No email situations found.', 'email type taxonomy label', 'buddypress' ),
     2741        'no_terms'              => _x( 'No email situations', 'email type taxonomy label', 'buddypress' ),
     2742        'popular_items'         => _x( 'Popular Email Situation', 'email type taxonomy label', 'buddypress' ),
     2743        'search_items'          => _x( 'Search Emails', 'email type taxonomy label', 'buddypress' ),
     2744        'singular_name'         => _x( 'Email', 'email type taxonomy singular name', 'buddypress' ),
     2745        'update_item'           => _x( 'Update Email Situation', 'email type taxonomy label', 'buddypress' ),
     2746        'view_item'             => _x( 'View Email Situation', 'email type taxonomy label', 'buddypress' ),
     2747    ) );
     2748}
    25952749/**
    25962750 * Return email appearance settings.
     
    26282782    );
    26292783}
     2784
     2785/**
     2786 * Get the paths to possible templates for the specified email object.
     2787 *
     2788 * @since 2.5.0
     2789 *
     2790 * @param WP_Post $object Post to get email template for.
     2791 * @return string[]
     2792 */
     2793function bp_email_get_template( WP_Post $object ) {
     2794    $single = "single-{$object->post_type}";
     2795
     2796    /**
     2797     * Filter the possible template paths for the specified email object.
     2798     *
     2799     * @since 2.5.0
     2800     *
     2801     * @param string[] $templates
     2802     */
     2803    return apply_filters( 'bp_email_get_template', array(
     2804        "{$single}-{$object->post_name}.php",
     2805        "{$single}.php",
     2806        "assets/emails/{$single}.php",
     2807    ), $object );
     2808}
  • trunk/src/bp-core/bp-core-loader.php

    r10417 r10474  
    285285
    286286        parent::setup_cache_groups();
     287    }
     288
     289    /**
     290     * Set up post types.
     291     *
     292     * @since BuddyPress (2.4.0)
     293     */
     294    public function register_post_types() {
     295
     296        // Emails
     297        register_post_type(
     298            bp_get_email_post_type(),
     299            apply_filters( 'bp_register_email_post_type', array(
     300                'description'       => _x( 'BuddyPress emails', 'email post type description', 'buddypress' ),
     301                'labels'            => bp_get_email_post_type_labels(),
     302                'menu_icon'         => 'dashicons-email',
     303                'public'            => false,
     304                'publicly_queryable' => bp_current_user_can( 'bp_moderate' ),
     305                'query_var'         => false,
     306                'rewrite'           => false,
     307                'show_in_admin_bar' => false,
     308                'show_ui'           => bp_current_user_can( 'bp_moderate' ),
     309                'supports'          => bp_get_email_post_type_supports(),
     310            ) )
     311        );
     312
     313        parent::register_post_types();
    287314    }
    288315}
  • trunk/src/bp-core/bp-core-taxonomy.php

    r10417 r10474  
    2525        'public' => false,
    2626    ) );
     27
     28    // Email type.
     29    register_taxonomy(
     30        bp_get_email_tax_type(),
     31        bp_get_email_post_type(),
     32        apply_filters( 'bp_register_email_tax_type', array(
     33            'description'   => _x( 'BuddyPress email types', 'email type taxonomy description', 'buddypress' ),
     34            'labels'        => bp_get_email_tax_type_labels(),
     35            'meta_box_cb'   => 'bp_email_tax_type_metabox',
     36            'public'        => false,
     37            'query_var'     => false,
     38            'rewrite'       => false,
     39            'show_in_menu'  => false,
     40            'show_tagcloud' => false,
     41            'show_ui'       => bp_current_user_can( 'bp_moderate' ),
     42        ) )
     43    );
    2744}
    2845add_action( 'bp_register_taxonomies', 'bp_register_default_taxonomies' );
  • trunk/src/bp-core/bp-core-update.php

    r10417 r10474  
    214214        bp_update_option( 'bp-active-components', $default_components );
    215215        bp_core_add_page_mappings( $default_components, 'delete' );
     216        bp_core_install_emails();
    216217
    217218    // Upgrades
     
    260261        if ( $raw_db_version < 9615 ) {
    261262            bp_update_to_2_3();
     263        }
     264
     265        // 2.5.0
     266        if ( $raw_db_version < 10440 ) {
     267            bp_update_to_2_5();
    262268        }
    263269    }
     
    482488        bp_core_install_notifications();
    483489    }
     490}
     491
     492/**
     493 * 2.5.0 update routine.
     494 *
     495 * - Add emails.
     496 *
     497 * @since 2.5.0
     498 */
     499function bp_update_to_2_5() {
     500    bp_core_install_emails();
    484501}
    485502
  • trunk/src/bp-loader.php

    r10417 r10474  
    423423        $this->current_user   = new stdClass();
    424424        $this->displayed_user = new stdClass();
     425
     426        /** Post types and taxonomies *****************************************/
     427        $this->email_post_type     = apply_filters( 'bp_email_post_type', 'bp-email' );
     428        $this->email_taxonomy_type = apply_filters( 'bp_email_tax_type', 'bp-email-type' );
    425429    }
    426430
Note: See TracChangeset for help on using the changeset viewer.