Skip to content

Commit

Permalink
feat: add non pretty url
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrisbee committed Dec 11, 2023
1 parent 810514a commit 7ee5dab
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Requests/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ protected function request(

$response = $http->{$method}($this->getUrl($path), $options);

if (!($response instanceof Response)) {
throw new UnexpectedValueException();
if (!($response instanceof Response) || $response->json() === null) {
$response = $http->{$method}($this->getNonPrettyUrl($path), $options);

if ((!($response instanceof Response) || $response->json() === null)) {
throw new UnexpectedValueException();
}
}

if (!$response->successful()) {
Expand Down Expand Up @@ -82,6 +86,15 @@ public function getUrl(string $path): string
);
}

public function getNonPrettyUrl(string $path): string
{
return sprintf('%s?rest_route=/wp/%s/%s',
rtrim($this->app->site(), '/'),
self::VERSION,
ltrim($path, '/')
);
}

/**
* @param array<string, array<int, string>> $headers
*
Expand Down

0 comments on commit 7ee5dab

Please sign in to comment.