Exclude rest api route programmatically
-
I’m developing a plugin, that need to expose some rest api endpoints. I want to programmatically exclude some routes from caching.
I’m using JWT Auth Plugin for auth management.
I’m registering following route:
register_rest_route( 'something/v1', '/saved-searches', array( 'methods' => 'GET', 'callback' => 'listSavedSearches', ));
This is how I exclude the request path/page from cache.
function listSavedSearches() { do_action( 'litespeed_control_set_nocache', 'nocache due to logged in' ); ... //some code wp_send_json(['sucess' => true, 'results' => $saved_searches],200); }
So far so good, I get the non-cached results fine.
However, if I send the wrong auth token in the header, causing
jwt_auth_invalid_token
the callbacklistSavedSearches()
never called, so it doesn’tset_nocache
, and goes to back as 403 unauthorised, but also its cached for future calls.All subsequent calls, even with a valid token are responded with 403.
How can I avoid that?PS: If I write the path to plugin setting by going into
LightSpeed Plugin > Cache > Exclude > Do Not Cache URIs
It works, but I’ve more than few endpoints that I want to exclude from cache, so I’m looking for programmatic solution.
- The topic ‘Exclude rest api route programmatically’ is closed to new replies.