Skip to content

Commit

Permalink
update request
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrisbee committed Nov 15, 2023
1 parent ed7c791 commit b13caf7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/Facades/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Storipress\WordPress\Requests\Tag;
use Storipress\WordPress\Requests\User;


/**
* @method static Post post()
* @method static Category category()
Expand Down
19 changes: 18 additions & 1 deletion src/Objects/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, 'subscriber'|'contributor'|'author'|'editor'|'administrator'>
*/
public array $roles;

public stdClass $avatar_urls;
}
12 changes: 8 additions & 4 deletions src/Requests/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
]);
}
}
14 changes: 9 additions & 5 deletions src/Requests/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
]);
}
}
12 changes: 8 additions & 4 deletions src/Requests/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
]);
}
}
13 changes: 9 additions & 4 deletions src/Requests/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
]);
}
}

0 comments on commit b13caf7

Please sign in to comment.