Custom endpoint registered, not caching
-
Hello, I have the following endpoint: ‘products’ in the namespace: ‘wc/v3/ext’
I am using the following to register the route and enable caching.
I can access the endpoint successfully; I can confirm through debugging that the namespace and endpoint are added to the allowed endpoints.
The plugin is activated.
I have yet to be able to cache a response.
public static function RegisterRoute( string $namespace, string $endpoint, array $methods, object $handler, bool $enableCache = false ) {
add_action('rest_api_init', function () use ($namespace, $endpoint, $methods, $handler) {
register_rest_route($namespace, '/' . $endpoint, array(
'methods' => $methods,
'callback' => array($handler, 'wcre_endpoint_callback')
));
});
if( $enableCache ) {
add_filter( 'wp_rest_cache/allowed_endpoints', function ($allowed_endpoints) use ($namespace, $endpoint) {
if ( ! isset ( $allowed_endpoints[ $namespace ] ) || ! in_array( $endpoint, $allowed_endpoints[ $namespace ] ) ) {
$allowed_endpoints[ $namespace ][] = $endpoint;
}
return $allowed_endpoints;
}, 10, 1 );
}
}
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.