Hey @hartl! 👋
Make sure you haven’t disabled the cache in the lightbox settings, otherwise the nonce must be valid to fetch your media data. If the cache is enabled, no request will be made after the data has already been cached, this should solve your issue.
Setting the Rendering Delay to 0 will completely turn off the media request, so if nothing is cached, it results in empty lightbox data.
The next version of the lightbox will include an option to completely bypass any request while still rendering your media in the lightbox. For now, enabling the cache should solve your issue.
Hope this helps!
Thread Starter
thartl
(@hartl)
Hi @valwa,
Thank you for the suggestion. However, on all sites where this issue is occurring the plugin’s cache is NOT disabled. The issue is with full-page caching.
When a page with Meow Lightbox images is first cached, that includes the nonce at that time. Then 12-24 hours later that nonce becomes stale, which leads to the 403 errors.
In my opinion the solution is not using X-WP-Nonce in your regenerate_mwl_data POST request. There may be other solutions, but that would seem sensible for guest users at least.
Hey @hartl! 👋
The regenerate_mwl_data route already does not have a permission callback, so if you want to bypass any nonce check you can use a filter like this:
add_filter( 'rest_authentication_errors', function ( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
$uri = $_SERVER['REQUEST_URI'] ?? '';
if ( strpos( $uri, '/wp-json/meow-lightbox/v1/regenerate_mwl_data' ) !== false ) {
return true; // bypass cookie auth for this route
}
return $result;
}, 99 );
That said, rather than doing this, I would recommend using the plugin cache and Output Buffering and disabling REST calls, so no REST request is made if a page already has the needed lightbox data. You can learn more about this here: https://photo.thehiddendocs.com/tutorials/dynamic-media-loading/
Hope this helps!