Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Last active June 15, 2021 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zackkatz/9b48e8714504a503f92eb63e471a66e9 to your computer and use it in GitHub Desktop.
Save zackkatz/9b48e8714504a503f92eb63e471a66e9 to your computer and use it in GitHub Desktop.
GravityView Calendar - Modify the settings for a single event
<?php
/**
* Modify event array that is output to FullCalendar
* In this sample code, we add a background color to a specific event
*
* @param array $events Array of events.
* @param object $form Calendar form.
* @param object $feed Calendar feed.
* @param array $field_map Array of feed fields mapped to calendar settings (e.g., start_time, end_time).
* @param array $entries Array of entries being displayed in the calendar (Requires 1.5.2)
*
* @return array $events Modified events
*/
add_filter( 'gravityview/calendar/events', function ( $events, $form, $feed, $field_map = array(), $entries = array() ) {
if ( empty( $events ) || empty( $entries ) ) {
return;
}
$event_ids = wp_list_pluck( $events, 'event_id' );
foreach ( $entries as $entry ) {
$event_key = array_search( $entry->ID, $event_ids );
if ( false === $event_key ) {
continue;
}
// Modify event color if field ID #1 value is "some value"
if ( 'some value' === $entry[1] ) {
$events[ $event_key ]['backgroundColor'] = 'red';
$events[ $event_key ]['borderColor'] = 'blue';
$events[ $event_key ]['textColor'] = 'yellow';
}
}
return $events;
}, 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment