Hello,
I’m in the process of building a listing site using a paid theme (“citadela” by ait-themes.club/). It comes with a few plugins which are necessary to extend the theme to become a listing site.
To test the theme, I installed it on a normal fresh WordPress installation locally using Valet and PHP 8. Everything worked fine.
However, once I’ve decided to stick with the theme and put together a more professional environment with Bedrock, the theme can’t reach certain API endpoints. In this case, it was the endpoint to fetch items.
This fails and throws the following error message in Chrome’s console:
Uncaught (in promise) SyntaxError: Unexpected token '<', "<br />
<b>"... is not valid JSON
This was created by Valet’s error message, which is:
<br />
<b>Warning</b>: chdir(): No such file or directory (errno 2) in <b>/Users/kolja/.composer/vendor/laravel/valet/server.php</b> on line <b>232</b><br />
<br />
<b>Warning</b>: require(/Users/kolja/Sites/mysite.com/web/wp/wp-json/citadela-directory/map-data/points/citadela-item): Failed to open stream: No such file or directory in <b>/Users/kolja/.composer/vendor/laravel/valet/server.php</b> on line <b>234</b><br />
<br />
<b>Fatal error</b>: Uncaught Error: Failed opening required '/Users/kolja/Sites/mysite.com/web/wp/wp-json/citadela-directory/map-data/points/citadela-item' (include_path='.:/opt/homebrew/Cellar/php@8.0/8.0.20/share/php@8.0/pear') in /Users/kolja/.composer/vendor/laravel/valet/server.php:234
Stack trace:
#0 {main}
thrown in <b>/Users/kolja/.composer/vendor/laravel/valet/server.php</b> on line <b>234</b><br />
As you can see, the fatal error is caused by the request of the URL /web/wp/wp-json/citadela-directory/map-data/points/citadela-item
.
Requesting this URL via the browser simply leads back to the front page with no error but still doesn’t access the endpoint.
Changing it to /wp-json/wp/v2/citadela-directory/
finally gives me a JSON object, but of course this custom route is not registered:
{
"code": "rest_no_route",
"message": "No route was found matching the URL and request method.",
"data": {
"status": 404
}
}
I’m quite certain that this has something to do with Bedrock being located in a subdirectory but I have no idea how to solve this. For reference, here is the code that handles the call (it’s inside one of the plugin extensions):
register_rest_route( 'citadela-directory', 'wp-json/map-data/points/citadela-item(?:/(?P<id>\d+))?', [
'methods' => 'GET',
'callback' => array(__CLASS__, 'restGetItemPoints'),
'permission_callback' => "__return_true",
'args' => ['id' => [
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
],
]
] );
Does anyone have an idea how I can fix this without editing the plugin itself and use Bedrock?
Many thanks!