Making WordPress.org

Changeset 6831


Ignore:
Timestamp:
03/07/2018 01:32:53 AM (8 years ago)
Author:
coreymckrill
Message:

WordCamp CampTix Tweaks: Add footer info to ticket receipt emails

Location:
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php

    r6714 r6831  
    33namespace WordCamp\CampTix_Tweaks;
    44use CampTix_Plugin;
     5use const WordCamp\Mentors\PLUGIN_DIR;
    56use WP_Post;
    67
     
    2021
    2122// Attendees
    22 add_filter( 'camptix_name_order',                            __NAMESPACE__ . '\set_name_order'         );
    23 add_action( 'camptix_form_edit_attendee_custom_error_flags', __NAMESPACE__ . '\disable_attendee_edits' );
    24 add_action( 'transition_post_status',                        __NAMESPACE__ . '\log_publish_to_cancel', 10, 3 );
     23add_filter( 'camptix_name_order',                            __NAMESPACE__ . '\set_name_order'                      );
     24add_action( 'camptix_form_edit_attendee_custom_error_flags', __NAMESPACE__ . '\disable_attendee_edits'              );
     25add_action( 'transition_post_status',                        __NAMESPACE__ . '\log_publish_to_cancel',        10, 3 );
    2526
    2627// Miscellaneous
    27 add_filter( 'camptix_beta_features_enabled', '__return_true' );
    28 add_action( 'camptix_nt_file_log',     '__return_false' );
    29 add_action( 'init',                    __NAMESPACE__ . '\camptix_debug', 9          ); // CampTix does this at 10.
    30 add_filter( 'camptix_default_addons',  __NAMESPACE__ . '\load_addons'               );
    31 add_filter( 'camptix_capabilities',    __NAMESPACE__ . '\modify_capabilities'       );
    32 add_filter( 'camptix_default_options', __NAMESPACE__ . '\modify_default_options'    );
    33 add_filter( 'camptix_html_message',    __NAMESPACE__ . '\render_html_emails', 10, 2 );
    34 add_action( 'camptix_tshirt_report_intro', __NAMESPACE__ . '\tshirt_report_intro_message', 10, 3 );
     28add_filter( 'camptix_beta_features_enabled',                 '__return_true' );
     29add_action( 'camptix_nt_file_log',                           '__return_false' );
     30add_action( 'init',                                          __NAMESPACE__ . '\camptix_debug',                    9 ); // CampTix does this at 10.
     31add_filter( 'camptix_default_addons',                        __NAMESPACE__ . '\load_addons'                         );
     32add_filter( 'camptix_capabilities',                          __NAMESPACE__ . '\modify_capabilities'                 );
     33add_filter( 'camptix_default_options',                       __NAMESPACE__ . '\modify_default_options'              );
     34add_filter( 'camptix_options',                               __NAMESPACE__ . '\modify_email_templates'              );
     35add_filter( 'camptix_email_tickets_template',                __NAMESPACE__ . '\switch_email_template'               );
     36add_filter( 'camptix_html_message',                          __NAMESPACE__ . '\render_html_emails',           10, 2 );
     37add_action( 'camptix_tshirt_report_intro',                   __NAMESPACE__ . '\tshirt_report_intro_message',  10, 3 );
    3538
    3639
     
    561564
    562565/**
     566 * Append a footer string to some email templates.
     567 *
     568 * This copies some email template strings from the options array into new array items where the key has
     569 * '_with_footer' appended. This ensures the footer is included in the desired templates without it getting
     570 * repeatedly appended to the option values every time the templates are customized.
     571 *
     572 * @param array $options
     573 *
     574 * @return array
     575 */
     576function modify_email_templates( $options ) {
     577    $sponsors_string = get_global_sponsors_string();
     578    $donation_string = get_donation_string();
     579
     580    $email_footer_string = "\n\n===\n\n$sponsors_string\n\n$donation_string";
     581
     582    $templates_that_need_footers = array(
     583        'email_template_single_purchase',
     584        'email_template_multiple_purchase',
     585        'email_template_multiple_purchase_receipt',
     586    );
     587
     588    foreach ( $templates_that_need_footers as $template ) {
     589        // We can't add the string to the original option or it will keep getting added over and over again
     590        // whenever the email templates are customized and saved.
     591        $options[ $template . '_with_footer' ] = $options[ $template ] . $email_footer_string;
     592    }
     593
     594    return $options;
     595}
     596
     597/**
     598 * Specify an alternate for email templates that should have our custom footer.
     599 *
     600 * @param string $template_slug
     601 *
     602 * @return string
     603 */
     604function switch_email_template( $template_slug ) {
     605    $templates_that_need_footers = array(
     606        'email_template_single_purchase',
     607        'email_template_multiple_purchase',
     608        'email_template_multiple_purchase_receipt',
     609    );
     610
     611    if ( in_array( $template_slug, $templates_that_need_footers, true ) ) {
     612        $template_slug .= '_with_footer';
     613    }
     614
     615    return $template_slug;
     616}
     617
     618/**
     619 * Get a string for HTML email footers listing global sponsors.
     620 *
     621 * @return string
     622 */
     623function get_global_sponsors_string() {
     624    $sponsor_message_html = '';
     625    $sponsors             = get_global_sponsors();
     626    $sponsor_count        = count( $sponsors );
     627
     628    if ( $sponsor_count > 0 ) {
     629        $sponsors = wp_list_pluck( $sponsors, 'name' );
     630
     631        shuffle( $sponsors );
     632
     633        switch ( $sponsor_count ) {
     634            case 1 :
     635                $sponsors_string = array_shift( $sponsors );
     636                break;
     637            case 2 :
     638                $sponsors_string = sprintf(
     639                    /* translators: The %s placeholders are the names of sponsors. */
     640                    __( '%s and %s', 'wordcamporg' ),
     641                    array_shift( $sponsors ),
     642                    array_shift( $sponsors )
     643                );
     644                break;
     645            default :
     646                $last_sponsor = array_pop( $sponsors );
     647
     648                $sponsors_string = sprintf(
     649                    '%1$s%2$s %3$s',
     650                    /* translators: Used between sponsor names in a list, there is a space after the comma. */
     651                    implode( _x( ', ', 'list item separator', 'wordcamporg' ), $sponsors ),
     652                    /* translators: List item separator, used before the last sponsor name in the list. */
     653                    __( ', and', 'wordcamporg' ),
     654                    $last_sponsor
     655                );
     656                break;
     657        }
     658
     659        $sponsor_message_html = sprintf(
     660            /* translators: The first %s placeholder is a list of sponsor names. The second %s placeholder is a URL. */
     661            __( 'WordPress Global Community Sponsors help fund WordCamps and meetups around the world. Thank you to %s for <a href="%s">their support</a>!', 'wordcamporg' ),
     662            $sponsors_string,
     663            'https://central.wordcamp.org/global-community-sponsors/'
     664        );
     665    }
     666
     667    return $sponsor_message_html;
     668}
     669
     670/**
     671 * Get a string for HTML email footers requesting donations to WPF.
     672 *
     673 * @return string
     674 */
     675function get_donation_string() {
     676    return sprintf(
     677        __( 'Do you love WordPress events? To support open source education and charity hackathons, please <a href="%s">donate to the WordPress Foundation</a>.', 'wordcamporg' ),
     678        'https://wordpressfoundation.org/donate/'
     679    );
     680}
     681
     682/**
     683 * Get an array of Global Sponsor names and URLs.
     684 *
     685 * @return array
     686 */
     687function get_global_sponsors() {
     688    $sponsors = array();
     689
     690    switch_to_blog( BLOG_ID_CURRENT_SITE );
     691
     692    $sponsor_posts = get_posts( array(
     693        'post_type'   => 'mes',
     694        'post_status' => 'publish',
     695        'numberposts' => -1,
     696    ) );
     697
     698    foreach ( $sponsor_posts as $sponsor_post ) {
     699        $sponsors[] = array(
     700            'name' => $sponsor_post->post_title,
     701            'url'  => $sponsor_post->mes_website,
     702        );
     703    }
     704
     705    restore_current_blog();
     706
     707    return $sponsors;
     708}
     709
     710/**
    563711 * Render an HTML message from the plain-text version
    564712 *
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/html-mail-header.php

    r2449 r6831  
    8282        }
    8383
     84        hr {
     85            margin: 2em auto;
     86            border: 0;
     87            height: 1px;
     88            background-color: #d3e7f8;
     89        }
     90
    8491        #bodyCell {
    8592            padding: 10px;
Note: See TracChangeset for help on using the changeset viewer.