Skip to content

Instantly share code, notes, and snippets.

@Apina
Last active December 18, 2015 07:39
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 Apina/273425ce2c2c62af6d17 to your computer and use it in GitHub Desktop.
Save Apina/273425ce2c2c62af6d17 to your computer and use it in GitHub Desktop.
Adds a Google Calendar button to the event registration display.php file. Updated with the help of Sidney, it now grabs the right times etc.
<?php
$ee_date_time_format = get_option('date_format') . " H:i";
$ee_start_date_time = DateTime::createFromFormat($ee_date_time_format, $all_meta['start_date'] . " " . $all_meta['start_time']);
$ee_end_date_time = DateTime::createFromFormat($ee_date_time_format, $all_meta['end_date'] . " " . $all_meta['end_time']);
$ee_start_date = $ee_start_date_time->getTimestamp();
$ee_end_date = $ee_end_date_time->getTimestamp();
$ee_startyear = date('Y', $ee_start_date);
$ee_startmonth = date('m', $ee_start_date);
$ee_startday = date('d', $ee_start_date);
$ee_starttime = gmdate('His', $ee_start_date);
$ee_endyear = date('Y', $ee_end_date);
$ee_endmonth = date('m', $ee_end_date);
$ee_endday = date('d', $ee_end_date);
$ee_endtime = gmdate('His', $ee_end_date);
$ee_fullstart = $ee_startyear . $ee_startmonth . $ee_startday . "T" . $ee_starttime . "Z";
$ee_fullend = $ee_endyear . $ee_endmonth . $ee_endday . "T" . $ee_endtime . "Z";
?>
<?php
//NEEDED
$ee_orgname = get_option('events_organization_settings');
$ee_orgname = $orgname['organization'];
if(!isset($event->venue_name)) {
$ee_venue = array();
if (!empty($all_meta['venue_title']))
$ee_venue[] = $all_meta['venue_title'];
if (!empty($all_meta['venue_address']))
$ee_venue[] = $all_meta['venue_address'];
if (!empty($all_meta['venue_address2']))
$ee_venue[] = $all_meta['venue_address2'];
if (!empty($all_meta['venue_city']))
$ee_venue[] = $all_meta['venue_city'];
if (!empty($all_meta['venue_state']))
$ee_venue[] = $all_meta['venue_state'];
if (!empty($all_meta['venue_zip']))
$ee_venue[] = $all_meta['venue_zip'];
if (!empty($all_meta['venue_country']))
$ee_venue[] = $all_meta['venue_country'];
$ee_location = implode($ee_venue, ',');
} else {
$ee_location = $event->venue_name;
}
$desc = htmlspecialchars(strip_shortcodes(wp_strip_all_tags($all_meta['event_desc'])));
echo $desc;
?>
<a href="http://www.google.com/calendar/event?action=TEMPLATE&text=<?php echo $all_meta['event_name']; ?>&dates=<?php echo $ee_fullstart; ?>/<?php echo $ee_fullend; ?>&details=<?php echo $desc; ?>&location=<?php echo $ee_location; ?>&trp=false&sprop=<?php echo $ee_orgname; ?>&sprop=name:<?php echo site_url(); ?>" target="_blank"><img src="//www.google.com/calendar/images/ext/gc_button3.gif" border=0></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment