As a follow up, I installed the following code in my wp-rest.php file to identify the end point I want cached. It it is derived from the URL of the end point above:
/**
* Register the /wp-json/app/v1/pwp-manifest endpoint so it will be cached.
*/function wprc_add_app_manifest_endpoint( $allowed_endpoints ) {
if ( ! isset( $allowed_endpoints[ ‘app/v1’ ] ) ||
! in_array( ‘posts’, $allowed_endpoints[ ‘app/v1’ ] ) ) {
$allowed_endpoints[ ‘app/v1’ ][] = ‘manifest’;
}
return $allowed_endpoints;
}add_filter( ‘wp_rest_cache/allowed_endpoints’, ‘wprc_add_app_manifest_endpoint’, 10, 1);
As a result I see the following in the cache of the WP REST Cache plugin:
Cache Key:
aad60a08557f4c0d3871114b201d7f19
Request URI:
/wp-json/wp/v2/posts/11118?_fields=title
Request Headers
{“\/wp-json\/app\/v1\/pwp-manifest”:null}
Request Method:
GET
Object Type:
unknown
Expiration:
2021-10-30 08:48:16
# Cache Hits
4
Active
check mark
Is this the expected output? The reasons I am asking are as follows:
(1) The word “null” appears in the line under request headers.
(2) The object type is reported as “unknown”.
(3) I tested in GTmetrix and the https://www.ocalahomes.online/wp-json/app/v1/pwp-manifest end point URL is not being reported as loading any quicker.
Thanks in advance for any clarifications anyone can offer.
Hi @aakrealtor
The results you are seeing in the cache suggest to me that you have applied some other filter ( wp_rest_cache/cacheable_request_headers
). Since if you would have applied the filter wp_rest_cache/allowed_endpoints
the Request Headers wouldn’t contain your pwp-manifest endpoint.
Now looking at your code for the wp_rest_cache/allowed_endpoint
filter, I think you made an error there. In the comment you say you register the /wp-json/app/v1/pwp-manifest
endpoint, but in the actual code you left out the pwp-
part. So I guess you registered the wrong (non-exisiting?) endpoint /wp-json/app/v1/manifest
The correct code should be:
/**
* Register the /wp-json/app/v1/pwp-manifest endpoint so it will be cached.
*/
function wprc_add_app_manifest_endpoint( $allowed_endpoints ) {
if ( ! isset( $allowed_endpoints[ 'app/v1' ] ) || ! in_array( 'posts', $allowed_endpoints[ 'app/v1' ] ) ) {
$allowed_endpoints[ 'app/v1' ][] = 'pwp-manifest';
}
return $allowed_endpoints;
}
add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_app_manifest_endpoint', 10, 1 );