Thank you for the detailed information, @madjax. From what I’ve been able to troubleshoot so far this appears to be occurring due to how The Events Calendar plugin handles their views, which means how this plugin displays the calendar in the frontend. From the information I currently have this appears to be an issue related to how The Events Calendar plugin sets the $_SERVER['REQUEST_URI']
superglobal, which Cache Enabler relies on. Some of what I’ll detail below will be more technical, but that is just for completeness of detailing what I’ve concluded so far to reference at a later point. If the cache is empty the request looks like this:
1. https://www.example.com/events/
is requested.
2. Cache Enabler tries to deliver the /events/
cached page (e.g. wp-content/cache/cache-enabler/events/https-index.html
). In this process we use the $_SERVER['REQUEST_URI']
variable when checking if the cache exists, then if it has expired, and then if it needs to be bypassed.
3. The cached page doesn’t exist so Cache Enabler doesn’t deliver the cached page and instead starts capturing the page contents to cache the page. When the output buffer has ended, meaning when we are ready to take all of the captured page contents and save it as a static HTML file, we use the $_SERVER['REQUEST_URI']
variable to save the file to the server’s disk. The value we are receiving when all event views are enabled is //?post_type=tribe_events&eventDisplay=latest-past
in this example. (They do update this value a couple times through their View::setup_the_loop
method it looks like but that is the last value it’s updated to, at least when all event views are enabled with their updated calendar views.) In other event views we receive the same type of formatted value but with a different eventDisplay
parameter value. Cache Enabler takes the page path from this value received (by parsing it and taking the PHP_URL_PATH
value). In this case it’s empty, which is considered as the home page (same if it were just /
). This is why various pages from The Events Calendar are being saved as the home page. The cache expiry is not considered because we are checking the $_SERVER['REQUEST_URI']
value before it’s updated by The Events Calendar plugin, which in this example is /events/
.
In summary, the above means when all event views are enabled in The Events Calendar, Cache Enabler checks /events/
, believes it doesn’t exist, tries to capture the page, and is then told to save it as the home page from the value taken from the $_SERVER['REQUEST_URI']
variable that is no longer the original requested URI from the client.
The current recommend solution to work effectively with Cache Enabler would be updating The Events Calendar settings by going to the WordPress admin dashboard > Events > Settings and disable the “Use updated calendar designs” setting. This makes this plugin work with Cache Enabler by allowing each view to be cached and delivered correctly (regardless of what event views are enabled).
If you don’t want to disable the setting above, one workaround I’ve found so far that can be implemented to resolve this specific issue for the time being would be adding the following snippet to your website, like in your functions.php
file:
add_filter( 'cache_enabler_bypass_cache', 'cache_enabler_exclude_events_calendar' );
function cache_enabler_exclude_events_calendar() {
$events_calendar_regex = '#//\?post_type=tribe_events&.+#';
$request_uri = $_SERVER['REQUEST_URI'];
if ( preg_match( $events_calendar_regex, $request_uri ) ) {
return true;
}
}
That snippet just excludes all of the calendar pages from the cache and is not the prettiest solution. (Unfortunately excluding the page paths in Cache Enabler doesn’t work due to how they update the superglobal, unless you disable one of the event views, to which you could then exclude /^\/events\/.*$/
.)
I’d love to come up with a better solution but I’m not familiar with The Events Calendar, so if you want to reach out to them and see if they have a different solution or even already know how to effectively cache their event pages with the updated calendar views that’d be great.