Adding Custom Properties For The Calendar Object

⚠️ This is a developer-level document. We may not be able to provide support for techniques and information outlined here.

In Pie Calendar, you can add custom properties to the calendar's JavaScript via the piecal_calendar_object_properties filter.

Here's an example from the Pro plugin, which adds support for the hidePastEvents attribute:

add_filter( 'piecal_calendar_object_properties', 'piecalHidePastEvents', 10, 4);

function piecalHidePastEvents( $properties, $eventsArray, $appendOffset, $atts ) {
    if( !isset( $atts['hidepastevents'] ) || $atts['hidepastevents'] == false ) {
        return $properties;
    }

    $newProp = "
    validRange: {
        start: new Date()
    },
    ";

    $properties = [...$properties, $newProp];

    return $properties;
}

Important notes:

  1. The new property must be a string, and it must have a comma at the end of the string (this allows other properties to be injected later without issues.)
  2. The new property must be appended to the $properties array before returning it, since Pie Calendar loops through this array to output all of the custom property strings one after the other.

If you notice that your calendar won't load after adding a custom property this way, check on the commas in your custom properties to make sure they're present. If another custom property was added improperly prior to yours, then it could cause issues as well. It's best to check the browser console in case of errors as it will identify where the issue lies so you can correct it.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.