How to block request for /wp-json?

I’ve actived the options to block all the requests for wp-json, but if i try to request without any parameter using the link “http://localhost/wp-json/” it returns all the endpoints, but if i try to request using “http://localhost/index.php?rest_route=/” it blocks it.

Is there a way to fix it without creating a hook?
In this case i want to solve using the actual plugin.

Used a workaround to block the access

function handle_rest_route_request($access)
{
if (!is_user_logged_in() && !current_user_can(‘administrator’)) {
return wp_die(__(‘Method not allowed.’, ‘joaopcos’), null, array(‘response’ => 403));
}

return $access;
}

add_filter(‘rest_authentication_errors’, ‘handle_rest_route_request’, 10);

1 Like