Trying to check if REST API is active from a plugin, causes a time out
-
Hopefully, that’s the right forum where to ask for help.
As part of a plugin features, I need to provide some REST endpoints.
However, I need to check first if REST API is active in the running site (since they can be disabled in many ways) and provide feedback to the administrator.
To do that, I first check if
rest_get_server()->get_routes()
returns anything.If I get nothing, that’s enough for the plugin to know that REST API can’t be used on that site.
However, if I get something, I suppose I still need to check if I can actually use the REST API.
To do so, I thought I can simply send a discovery request.Using a simple REST client, if I send a GET request to
domain.tld/wp-json
(wheredomain.tld
is my development site), I get what is documented here.However, if, from the same development site, I run the same request via PHP (
$response = $this->http->get( get_site_url() . '/wp-json', array( 'timeout' => 10) );
) through the plugin, this request times out.
No matter what timeout value I set, it eventually returns a WP_Error object withcURL error 28: Operation timed out after 10002 milliseconds with 0 bytes received
as the error message.Am I doing anything wrong?
Does WP provide a better (server-side) way to check if REST API can be used on the running site?
- The topic ‘Trying to check if REST API is active from a plugin, causes a time out’ is closed to new replies.