Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created July 31, 2018 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/d6eb3c46b419940b7708c9b9c0405284 to your computer and use it in GitHub Desktop.
Save joshfeck/d6eb3c46b419940b7708c9b9c0405284 to your computer and use it in GitHub Desktop.
Example code showing how to put together a new custom shortcode for EE3 emails, [custom_attendee_event_list]
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_filter(
'filter_hook_espresso_post_replace_shortcode_search_values',
'my_custom_attendee_event_list_shortcode_search_value',
10
);
add_filter(
'filter_hook_espresso_post_replace_shortcode_replace_values',
'my_custom_attendee_event_list_shortcode_replace_value',
10,
2
);
function my_custom_attendee_event_list_shortcode_search_value($SearchValues) {
$SearchValues[] = "[custom_attendee_event_list]";
return $SearchValues;
}
function my_custom_attendee_event_list_shortcode_replace_value($ReplaceValues, $data) {
$custom_event_table = my_custom_event_table_markup($data);
$ReplaceValues[] = $data->table_open
. $data->table_heading
. $custom_event_table
. $data->table_close;
return $ReplaceValues;
}
// modified copy/pasta from ee3 core follows
function my_custom_event_table_markup( $data ) {
global $wpdb;
$use_venue = isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? TRUE : FALSE;
$SQL = 'SELECT att.event_id, att.price_option, att.start_date, att.end_date, att.event_time, att.end_time, att.email, att.attendee_session, evt.id, evt.event_name ';
$SQL .= $use_venue ? ', v.name venue_name ' : ', evt.venue_title venue_name ';
$SQL .= 'FROM ' . EVENTS_ATTENDEE_TABLE . ' att ';
$SQL .= 'LEFT JOIN ' . EVENTS_DETAIL_TABLE . ' evt ON evt.id=att.event_id ';
$SQL .= $use_venue ? " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = evt.id LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = r.venue_id " : '';
$SQL .= 'WHERE att.email = %s AND att.attendee_session = %s';
$SQL .= 'ORDER BY att.start_date, att.event_time';
$events = $wpdb->get_results( $wpdb->prepare( $SQL, $data->attendee->email, $data->attendee->attendee_session ));
$table_row = '';
foreach ( $events as $event ) {
$table_row .= "
<tr>
<td>" . stripslashes_deep($event->event_name) . " | " . $event->price_option . "</td>
<td>" . event_date_display($event->start_date) . "</td>
<td>" . event_date_display($event->event_time, get_option('time_format')) . " - " . event_date_display($event->end_time, get_option('time_format')) . "</td>
<td>" . $event->venue_name . "<br />$data->location <br />$data->google_map_link</td>
</tr>";
}
$custom_questions = '';
//Output custom questions
if (function_exists('event_espresso_custom_questions_output')) {
//Create the question display
$email_questions_r = event_espresso_custom_questions_output(
array(
'attendee_id' => $data->attendee->id,
'all_questions' => TRUE
)
);
if ($email_questions_r != '') {
$custom_questions = '<tr><td colspan = "6">'
. $email_questions_r
. '</td></tr>';
}
}
return $table_row . $custom_questions;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment