From 7ee5dab7bda4013125ab09b4b177a8bcd141e70c Mon Sep 17 00:00:00 2001 From: Lyrisbee Date: Mon, 11 Dec 2023 09:18:08 +0800 Subject: [PATCH] feat: add non pretty url --- src/Requests/Request.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Requests/Request.php b/src/Requests/Request.php index 92f7106..14ed174 100644 --- a/src/Requests/Request.php +++ b/src/Requests/Request.php @@ -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()) { @@ -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> $headers *