I am attempting to retrieve a response within my custom plugin, as based on the REST routes provided by another plugin.
When running the following block of code in the root scope of my theme's function file I get a successful response with an expected outcome.
$request = new WP_REST_Request('GET', '/another/plugins/rest/route');
$request->set_query_params([
'filterBy' => [
'url' => '/test/'
]
]);
$response = rest_do_request($request);
But when running the exact block of code above in the root scope of my custom plugin file, I get a response of the following:
Array
(
[code] => rest_no_route
[message] => No route was found matching the URL and request method
[data] => Array
(
[status] => 404
)
)
I will note that my custom plugin should load after the other plugin that generated the REST routes, because my custom plugin's name comes alphabetically after the other plugin, and I have no code in place to change that order.
How do I get the rest routes to instantiate before my plugin is loaded?
add_action
/add_filter