diff --git a/src/Facades/WordPress.php b/src/Facades/WordPress.php index e43f430..4f84c38 100644 --- a/src/Facades/WordPress.php +++ b/src/Facades/WordPress.php @@ -10,7 +10,6 @@ use Storipress\WordPress\Requests\Tag; use Storipress\WordPress\Requests\User; - /** * @method static Post post() * @method static Category category() diff --git a/src/Objects/User.php b/src/Objects/User.php index f91cedf..bcdaad8 100644 --- a/src/Objects/User.php +++ b/src/Objects/User.php @@ -10,15 +10,32 @@ class User extends WordPressObject { public int $id; + public string $username; + public string $name; + public string $first_name; + + public string $last_name; + + public string $nickname; + + public string $slug; + + public string $email; + public string $url; public ?string $description; public string $link; - public string $slug; + public string $registered_date; + + /** + * @var array + */ + public array $roles; public stdClass $avatar_urls; } diff --git a/src/Requests/Category.php b/src/Requests/Category.php index b0b83f1..ebd47f6 100644 --- a/src/Requests/Category.php +++ b/src/Requests/Category.php @@ -57,11 +57,13 @@ public function create(array $arguments): CategoryObject * @throws HttpException * @throws UnexpectedValueException */ - public function retrieve(int $categoryId): CategoryObject + public function retrieve(int $categoryId, string $context = 'view'): CategoryObject { $uri = sprintf('/categories/%d', $categoryId); - $data = $this->request('get', $uri); + $data = $this->request('get', $uri, [ + 'context' => $context, + ]); if (is_array($data)) { throw new UnexpectedValueException(); @@ -97,10 +99,12 @@ public function update(int $categoryId, array $arguments): CategoryObject * @throws HttpException * @throws UnexpectedValueException */ - public function delete(int $categoryId): bool + public function delete(int $categoryId, bool $force = false): bool { $uri = sprintf('/categories/%d', $categoryId); - return $this->request('delete', $uri); + return $this->request('delete', $uri, [ + 'force' => $force, + ]); } } diff --git a/src/Requests/Post.php b/src/Requests/Post.php index 594dff2..973f61a 100644 --- a/src/Requests/Post.php +++ b/src/Requests/Post.php @@ -57,11 +57,13 @@ public function create(array $arguments): PostObject * @throws HttpException * @throws UnexpectedValueException */ - public function retrieve(int $postId): PostObject + public function retrieve(int $postId, string $context = 'view'): PostObject { $uri = sprintf('/posts/%d', $postId); - $data = $this->request('get', $uri); + $data = $this->request('get', $uri, [ + 'context' => $context, + ]); if (is_array($data)) { throw new UnexpectedValueException(); @@ -92,15 +94,17 @@ public function update(int $postId, array $arguments): PostObject } /** - * https://developer.wordpress.org/rest-api/reference/posts/#update-a-post + * https://developer.wordpress.org/rest-api/reference/posts/#delete-a-post * * @throws HttpException * @throws UnexpectedValueException */ - public function delete(int $postId): bool + public function delete(int $postId, bool $force = false): bool { $uri = sprintf('/posts/%s', $postId); - return $this->request('delete', $uri); + return $this->request('delete', $uri, [ + 'force' => $force, + ]); } } diff --git a/src/Requests/Tag.php b/src/Requests/Tag.php index 9a77471..95c4938 100644 --- a/src/Requests/Tag.php +++ b/src/Requests/Tag.php @@ -57,11 +57,13 @@ public function create(array $arguments): TagObject * @throws HttpException * @throws UnexpectedValueException */ - public function retrieve(int $tagId): TagObject + public function retrieve(int $tagId, string $context = 'view'): TagObject { $uri = sprintf('/tags/%d', $tagId); - $data = $this->request('get', $uri); + $data = $this->request('get', $uri, [ + 'context' => 'view', + ]); if (is_array($data)) { throw new UnexpectedValueException(); @@ -97,10 +99,12 @@ public function update(int $tagId, array $arguments): TagObject * @throws HttpException * @throws UnexpectedValueException */ - public function delete(int $tagId): bool + public function delete(int $tagId, bool $force = false): bool { $uri = sprintf('/tags/%d', $tagId); - return $this->request('delete', $uri); + return $this->request('delete', $uri, [ + 'force' => $force, + ]); } } diff --git a/src/Requests/User.php b/src/Requests/User.php index 10d5cb5..ac28b03 100644 --- a/src/Requests/User.php +++ b/src/Requests/User.php @@ -57,11 +57,13 @@ public function create(array $arguments): UserObject * @throws HttpException * @throws UnexpectedValueException */ - public function retrieve(int $userId): UserObject + public function retrieve(int $userId, string $context = 'view'): UserObject { $uri = sprintf('/users/%d', $userId); - $data = $this->request('get', $uri); + $data = $this->request('get', $uri, [ + 'context' => $context, + ]); if (is_array($data)) { throw new UnexpectedValueException(); @@ -97,10 +99,13 @@ public function update(int $userId, array $arguments): UserObject * @throws HttpException * @throws UnexpectedValueException */ - public function delete(int $userId): bool + public function delete(int $userId, int $reassign): bool { $uri = sprintf('/users/%d', $userId); - return $this->request('delete', $uri); + return $this->request('delete', $uri, [ + 'force' => true, + 'reassign' => $reassign, + ]); } }