Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active August 29, 2015 14:02
Show Gist options
  • Save Pebblo/050897965dbd9a6382cc to your computer and use it in GitHub Desktop.
Save Pebblo/050897965dbd9a6382cc to your computer and use it in GitHub Desktop.
Functions used to send emails when events are created or updated. Change lines 37 and 74 to the email address you wish to send the updates to.
<?php
function ee_event_created_email($params) {
global $wpdb;
$event_id = $params['event_id'];
if(empty($event_id)) {
return;
}
$sql = "SELECT evt.id, evt.event_name, evt.start_date, evt.end_date, se.start_time, se.end_time, v.name as venue_name, v.address, v.address2, v.city, v.state, v.zip FROM " . EVENTS_DETAIL_TABLE . " evt ";
$sql .= "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 .= "LEFT JOIN " . EVENTS_START_END_TABLE . " se ON se.event_id = evt.id ";
$sql .= "WHERE evt.id=" . $event_id;
$event = array_shift($wpdb->get_results($sql));
$body = "";
$body .= "<p>";
$body .= "EventId: " . $event->id . "<br/>";
$body .= "EventName: " . $event->event_name . "<br/>";
$body .= "StartDate: " . $event->start_date . "<br/>";
$body .= "EndDate: " . $event->end_date . "<br/>";
$body .= "StartTime: " . $event->start_time . "<br/>";
$body .= "EndTime: " . $event->end_time . "<br/>";
$body .= "</p>";
$body .= "<p>";
$body .= "VenueName: " . $event->venue_name . "<br/>";
$body .= "Address: " . $event->address . "<br/>";
$body .= "Address2: " . $event->address2 . "<br/>";
$body .= "City: " . $event->city . "<br/>";
$body .= "County: " . $event->state . "<br/>";
$body .= "Postcode: " . $event->zip . "<br/>";
$body .= "</p>";
$headers = "Content-Type: text/html; charset=utf-8\r\n";
wp_mail('[email protected]', "New event created", $body, $headers);
}
add_action("action_hook_espresso_insert_event_success", "ee_event_created_email");
function ee_event_update_email($event_id) {
global $wpdb;
if(empty($event_id)) {
return;
}
$sql = "SELECT evt.id, evt.event_name, evt.start_date, evt.end_date, se.start_time, se.end_time, v.name as venue_name, v.address, v.address2, v.city, v.state, v.zip FROM " . EVENTS_DETAIL_TABLE . " evt ";
$sql .= "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 .= "LEFT JOIN " . EVENTS_START_END_TABLE . " se ON se.event_id = evt.id ";
$sql .= "WHERE evt.id=" . $event_id;
$event = array_shift($wpdb->get_results($sql));
$body = "";
$body .= "<p>";
$body .= "EventId: " . $event->id . "<br/>";
$body .= "EventName: " . $event->event_name . "<br/>";
$body .= "StartDate: " . $event->start_date . "<br/>";
$body .= "EndDate: " . $event->end_date . "<br/>";
$body .= "StartTime: " . $event->start_time . "<br/>";
$body .= "EndTime: " . $event->end_time . "<br/>";
$body .= "</p>";
$body .= "<p>";
$body .= "VenueName: " . $event->venue_name . "<br/>";
$body .= "Address: " . $event->address . "<br/>";
$body .= "Address2: " . $event->address2 . "<br/>";
$body .= "City: " . $event->city . "<br/>";
$body .= "County: " . $event->state . "<br/>";
$body .= "Postcode: " . $event->zip . "<br/>";
$body .= "</p>";
$headers = "Content-Type: text/html; charset=utf-8\r\n";
wp_mail('[email protected]', "Event updated", $body, $headers);
}
add_action("action_hook_espresso_update_event_success_id", "ee_event_update_email");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment