Skip to content

Instantly share code, notes, and snippets.

@alanef
Last active October 5, 2021 11:06
Show Gist options
  • Select an option

  • Save alanef/f1a349d80f49b9ef3506dda40eb9effa to your computer and use it in GitHub Desktop.

Select an option

Save alanef/f1a349d80f49b9ef3506dda40eb9effa to your computer and use it in GitHub Desktop.
/**
* Filter to modify the returned data from Display Eventbrite
* to take the day of the start date and apply it to teh end of teh last day of
* multi day events
*
* So the event appears as a single bookable entry in calendar layouts
*
*/
add_filter(
'wfea_api_results', // hook to filter returned event data before display
/**
* @param $events
* @param $atts
*
* @return mixed
* @throws Exception
*/
function ( $events, $atts ) {
if ( ! in_array(
$atts['layout'],
array(
'cal_list',
'cal'
)
) ) { // only impact cal_list and cal layout
return $events;
}
foreach ( $events as $key => $event ) {
$start = new \DateTime( $event->start->utc );
$end = new \DateTime( $event->end->utc );
$start_day = $start->format( 'Y-m-d' );
$end_day = $end->format( 'Y-m-d' );
if ( $start_day != $end_day ) {
/**
* multiday event found
* need to grab end time from end date
* and rebuild both local and utc end date/time
*/
$start_local = new \DateTime( $event->start->local );
$start_day_local = $start_local->format( 'Y-m-d' );
$end_local = new \DateTime( $event->end->local );
$end_time = $end->format( 'H:i:s' );
$end_time_local = $end_local->format( 'H:i:s' );
$events[ $key ]->end->utc = $start_day . 'T' . $end_time . 'Z';
$events[ $key ]->end->local = $start_day_local . 'T' . $end_time_local;
}
}
return $events;
},
10, // priority
2 // two arguments
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment