The Simple Calendar plugin caches the Google Calendar data, or rather the feed, using WordPress transients. This is mainly so as to improve the performance of the plugin and also reduce API calls.
Once changes are made to your Google calendar, these are not immediately reflected on the calendar within your site. In order to have these changes reflect, previously you would need to either clear the cache via the WordPress dashboard, as outlined here, or await expiry of the cache interval specified within your calendar. There was, however, no way for external systems (CI/CD pipelines, webhooks, automation scripts) to programmatically invalidate calendar caches.
With the REST API endpoint, the cache can now be cleared programmatically. This allows you to invalidate the cache instantly without logging into WordPress, making it easier to integrate with external workflows such as Google Workspace scripts or deployment pipelines.
Prerequisites
- Google Calendar Pro Addon (available from v1.4.4)
REST API Endpoint Structure
The endpoint would be structured as illustrated below:
GET|POST /wp-json/simple-calendar/v1/cache/clear
This endpoint triggers the plugin’s internal cache-clearing logic.
Authentication
Access to the endpoint requires authentication. The recommended approach is to use WordPress Application Passwords. Please note that you need to use the Application password and not the user password. Here is a guide on how to set up an application password if you don’t already have one.
The authenticated user must also have the edit_posts capability.
Parameters
| Parameter | Type | Required | Description |
| username | string | Yes | WordPress username |
| password | string | Yes | WordPress Application Password for the user |
| calendar_ids | string or array | Yes | Calendar post ID(s) to clear cache for |
Example Requests
GET (comma-separated IDs):
https://example.com/wp-json/simple-calendar/v1/cache/clear?username=admin&password=XXXX%20XXXX%20XXXX%20XXXX%20XXXX%20XXXX&calendar_ids=29,42
POST (JSON body):
curl -X POST https://example.com/wp-json/simple-calendar/v1/cache/clear \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "XXXX XXXX XXXX XXXX XXXX XXXX", "calendar_ids": [29, 42]}'
– In the above requests, you will notice that the username, application password, and the calendar IDs are parsed in the request.
– POST is preferred over GET since GET requests expose the password in URLs, which can be logged by browsers, servers, and proxies.
What Happens Internally
When the endpoint is called, the plugin clears its cached data (stored as transients). This ensures that the next time a calendar is loaded, fresh data is pulled from Google Calendar.
Responses
All responses follow the same structure: code, message, and data (with status inside data).
Success (200): Rendered if all checks are passed and the calendar cache is successfully cleared.
{
"code": "cache_cleared",
"message": "Cache cleared for 2 calendar(s).",
"data": {
"status": 200,
"calendar_ids": [29, 42]
}
}
Invalid credentials (403): Rendered if the credentials used in the request are not correct. For example, if the user password is used instead of the Application password.
{
"code": "rest_forbidden",
"message": "Invalid username or application password.",
"data": { "status": 403 }
}
Insufficient permissions (403): Rendered if the user whose credentials are passed into the request does not have permission to edit posts or rather the calendars post type.
{
"code": "rest_forbidden",
"message": "You do not have permission to clear calendar caches.",
"data": { "status": 403 }
}
Invalid calendar IDs (400): Rendered if the calendar IDs parsed into the request are not present within the site.
{
"code": "rest_invalid_param",
"message": "calendar_ids must be a non-empty array of integers or a comma-separated string.",
"data": { "status": 400 }
}
Notes
– Application Passwords require HTTPS or WP_ENVIRONMENT_TYPE set to local in wp-config.php. The development environment type is not sufficient.
– This clears plugin-level cache only. It does NOT clear page cache (e.g., WP Rocket, LiteSpeed) or CDN cache (e.g., Cloudflare)