Skip to main content

Download a show’s Content Calendar as iCal, or read its private subscription URL

Premium Advanced Content Calendar

The routes behind a show’s iCal export and its private subscription feed: GET /benecaster-content-calendar/v1/shows/{show_id}/ical, and GET and POST …/shows/{show_id}/ical/subscription. They need the same permission and per-show check as Read and write a show’s Content Calendar content items over REST: manage_options and the REST nonce, and Content Calendar switched on for {show_id}, else 403 benecaster_content_calendar_off_for_show.

The download. GET …/ical answers { filename, content }. content is the show’s whole calendar as iCalendar text (RFC 5545); filename is {show-slug}-content-calendar.ics. In it:

  • Every item of the show’s switched-on types, whatever its date or status.
  • One entry on the item’s publish date, titled Type: Title (Status), and a second on its due date when it has one, titled Due: Type: Title (Status).
  • A Canceled item’s entries are STATUS:CANCELLED.
  • An all-day entry is a VALUE=DATE day; a timed one is converted from the site’s time zone to UTC (…Z).

UIDs are permanent: benecaster-content-calendar-item-{id}@{host} and benecaster-content-calendar-item-{id}-due@{host}, with {host} from home_url(). benecaster-content-calendar-episode-{id}@{host} and benecaster-content-calendar-episode-{id}-tier-{tier}@{host} are reserved for episodes and tier dates.

The subscription URL. GET …/ical/subscription answers { url }, the show’s private subscription URL, made the first time it is asked for. POST replaces it, and the old one stops working at once. The URL is {home_url}/?benecaster_calendar_feed={show_id}&key={64 hex characters}. It serves the same calendar as text/calendar with no login, and answers 404 for a wrong or replaced key, another show’s key, or a show with Content Calendar off. The routes answer 500 benecaster_content_calendar_feed_unavailable when Benecaster cannot store secrets on the site; the key is kept with benecaster_store_secret() under ical_key_{show_id}.

To add or change entries in the download and the feed, see Add to or change the entries in a show’s Content Calendar iCal export and subscription feed.

Code

// From an admin screen, with core's nonce.
const root = benecasterAdmin.apiUrl.replace( /benecaster\/v1\/?$/, '' );
const { filename, content } = await ( await fetch( `${ root }benecaster-content-calendar/v1/shows/${ showId }/ical`, {
    credentials: 'same-origin',
    headers: { 'X-WP-Nonce': benecasterAdmin.nonce },
} ) ).json();

View on GitHub →

Need this built rather than just documented? See our services →