<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[6831] sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks: WordCamp CampTix Tweaks: Add footer info to ticket receipt emails</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/6831">6831</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/6831","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>coreymckrill</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-03-07 01:32:53 +0000 (Wed, 07 Mar 2018)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WordCamp CampTix Tweaks: Add footer info to ticket receipt emails</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentmupluginscamptixtweakscamptixtweaksphp">sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentmupluginscamptixtweaksviewshtmlmailheaderphp">sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/html-mail-header.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentmupluginscamptixtweakscamptixtweaksphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php      2018-03-05 21:22:50 UTC (rev 6830)
+++ sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php        2018-03-07 01:32:53 UTC (rev 6831)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,6 +2,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordCamp\CampTix_Tweaks;
</span><span class="cx" style="display: block; padding: 0 10px"> use CampTix_Plugin;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use const WordCamp\Mentors\PLUGIN_DIR;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WP_Post;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> defined( 'WPINC' ) or die();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,19 +20,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'camptix_payment_result',                        __NAMESPACE__ . '\track_payment_results',        10, 3 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Attendees
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'camptix_name_order',                            __NAMESPACE__ . '\set_name_order'         );
-add_action( 'camptix_form_edit_attendee_custom_error_flags', __NAMESPACE__ . '\disable_attendee_edits' );
-add_action( 'transition_post_status',                        __NAMESPACE__ . '\log_publish_to_cancel', 10, 3 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'camptix_name_order',                            __NAMESPACE__ . '\set_name_order'                      );
+add_action( 'camptix_form_edit_attendee_custom_error_flags', __NAMESPACE__ . '\disable_attendee_edits'              );
+add_action( 'transition_post_status',                        __NAMESPACE__ . '\log_publish_to_cancel',        10, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Miscellaneous
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'camptix_beta_features_enabled', '__return_true' );
-add_action( 'camptix_nt_file_log',     '__return_false' );
-add_action( 'init',                    __NAMESPACE__ . '\camptix_debug', 9          ); // CampTix does this at 10.
-add_filter( 'camptix_default_addons',  __NAMESPACE__ . '\load_addons'               );
-add_filter( 'camptix_capabilities',    __NAMESPACE__ . '\modify_capabilities'       );
-add_filter( 'camptix_default_options', __NAMESPACE__ . '\modify_default_options'    );
-add_filter( 'camptix_html_message',    __NAMESPACE__ . '\render_html_emails', 10, 2 );
-add_action( 'camptix_tshirt_report_intro', __NAMESPACE__ . '\tshirt_report_intro_message', 10, 3 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'camptix_beta_features_enabled',                 '__return_true' );
+add_action( 'camptix_nt_file_log',                           '__return_false' );
+add_action( 'init',                                          __NAMESPACE__ . '\camptix_debug',                    9 ); // CampTix does this at 10.
+add_filter( 'camptix_default_addons',                        __NAMESPACE__ . '\load_addons'                         );
+add_filter( 'camptix_capabilities',                          __NAMESPACE__ . '\modify_capabilities'                 );
+add_filter( 'camptix_default_options',                       __NAMESPACE__ . '\modify_default_options'              );
+add_filter( 'camptix_options',                               __NAMESPACE__ . '\modify_email_templates'              );
+add_filter( 'camptix_email_tickets_template',                __NAMESPACE__ . '\switch_email_template'               );
+add_filter( 'camptix_html_message',                          __NAMESPACE__ . '\render_html_emails',           10, 2 );
+add_action( 'camptix_tshirt_report_intro',                   __NAMESPACE__ . '\tshirt_report_intro_message',  10, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -560,6 +563,151 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Append a footer string to some email templates.
+ *
+ * This copies some email template strings from the options array into new array items where the key has
+ * '_with_footer' appended. This ensures the footer is included in the desired templates without it getting
+ * repeatedly appended to the option values every time the templates are customized.
+ *
+ * @param array $options
+ *
+ * @return array
+ */
+function modify_email_templates( $options ) {
+       $sponsors_string = get_global_sponsors_string();
+       $donation_string = get_donation_string();
+
+       $email_footer_string = "\n\n===\n\n$sponsors_string\n\n$donation_string";
+
+       $templates_that_need_footers = array(
+               'email_template_single_purchase',
+               'email_template_multiple_purchase',
+               'email_template_multiple_purchase_receipt',
+       );
+
+       foreach ( $templates_that_need_footers as $template ) {
+               // We can't add the string to the original option or it will keep getting added over and over again
+               // whenever the email templates are customized and saved.
+               $options[ $template . '_with_footer' ] = $options[ $template ] . $email_footer_string;
+       }
+
+       return $options;
+}
+
+/**
+ * Specify an alternate for email templates that should have our custom footer.
+ *
+ * @param string $template_slug
+ *
+ * @return string
+ */
+function switch_email_template( $template_slug ) {
+       $templates_that_need_footers = array(
+               'email_template_single_purchase',
+               'email_template_multiple_purchase',
+               'email_template_multiple_purchase_receipt',
+       );
+
+       if ( in_array( $template_slug, $templates_that_need_footers, true ) ) {
+               $template_slug .= '_with_footer';
+       }
+
+       return $template_slug;
+}
+
+/**
+ * Get a string for HTML email footers listing global sponsors.
+ *
+ * @return string
+ */
+function get_global_sponsors_string() {
+       $sponsor_message_html = '';
+       $sponsors             = get_global_sponsors();
+       $sponsor_count        = count( $sponsors );
+
+       if ( $sponsor_count > 0 ) {
+               $sponsors = wp_list_pluck( $sponsors, 'name' );
+
+               shuffle( $sponsors );
+
+               switch ( $sponsor_count ) {
+                       case 1 :
+                               $sponsors_string = array_shift( $sponsors );
+                               break;
+                       case 2 :
+                               $sponsors_string = sprintf(
+                                       /* translators: The %s placeholders are the names of sponsors. */
+                                       __( '%s and %s', 'wordcamporg' ),
+                                       array_shift( $sponsors ),
+                                       array_shift( $sponsors )
+                               );
+                               break;
+                       default :
+                               $last_sponsor = array_pop( $sponsors );
+
+                               $sponsors_string = sprintf(
+                                       '%1$s%2$s %3$s',
+                                       /* translators: Used between sponsor names in a list, there is a space after the comma. */
+                                       implode( _x( ', ', 'list item separator', 'wordcamporg' ), $sponsors ),
+                                       /* translators: List item separator, used before the last sponsor name in the list. */
+                                       __( ', and', 'wordcamporg' ),
+                                       $last_sponsor
+                               );
+                               break;
+               }
+
+               $sponsor_message_html = sprintf(
+                       /* translators: The first %s placeholder is a list of sponsor names. The second %s placeholder is a URL. */
+                       __( 'WordPress Global Community Sponsors help fund WordCamps and meetups around the world. Thank you to %s for <a href="%s">their support</a>!', 'wordcamporg' ),
+                       $sponsors_string,
+                       'https://central.wordcamp.org/global-community-sponsors/'
+               );
+       }
+
+       return $sponsor_message_html;
+}
+
+/**
+ * Get a string for HTML email footers requesting donations to WPF.
+ *
+ * @return string
+ */
+function get_donation_string() {
+       return sprintf(
+               __( 'Do you love WordPress events? To support open source education and charity hackathons, please <a href="%s">donate to the WordPress Foundation</a>.', 'wordcamporg' ),
+               'https://wordpressfoundation.org/donate/'
+       );
+}
+
+/**
+ * Get an array of Global Sponsor names and URLs.
+ *
+ * @return array
+ */
+function get_global_sponsors() {
+       $sponsors = array();
+
+       switch_to_blog( BLOG_ID_CURRENT_SITE );
+
+       $sponsor_posts = get_posts( array(
+               'post_type'   => 'mes',
+               'post_status' => 'publish',
+               'numberposts' => -1,
+       ) );
+
+       foreach ( $sponsor_posts as $sponsor_post ) {
+               $sponsors[] = array(
+                       'name' => $sponsor_post->post_title,
+                       'url'  => $sponsor_post->mes_website,
+               );
+       }
+
+       restore_current_blog();
+
+       return $sponsors;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Render an HTML message from the plain-text version
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string|false $html_message
</span></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentmupluginscamptixtweaksviewshtmlmailheaderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/html-mail-header.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/html-mail-header.php      2018-03-05 21:22:50 UTC (rev 6830)
+++ sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/html-mail-header.php        2018-03-07 01:32:53 UTC (rev 6831)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -81,6 +81,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        line-height: inherit !important;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                hr {
+                       margin: 2em auto;
+                       border: 0;
+                       height: 1px;
+                       background-color: #d3e7f8;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 #bodyCell {
</span><span class="cx" style="display: block; padding: 0 10px">                        padding: 10px;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span></span></pre>
</div>
</div>

</body>
</html>