Enable rest api endpoint for public read-only
-
Hi,
I want to use restricted access for REST API, but want to set an exclude, for one specific REST API endpoint, for public read-only. How can I do this?
I tried this but not work:
<?php
function allow_specific_rest_endpoint( $result, $request, $route, $handler ) {
$route = $request->get_route();
// Allow access if the route is /wp/v2/pages
if ( stripos( $route, 'wp/v2/pages' ) !== false ) {
return $result; // Allow the request to proceed
}
return $result; // Allow all other requests (default behavior)
}
add_filter( 'rest_dispatch_request', 'allow_specific_rest_endpoint', 99, 4 );
?>
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.