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-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}
Note: See TracChangeset for help on using the changeset viewer.