Skip to content

Commit

Permalink
Allow string argument for postTypes, taxonomies and postStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed Oct 19, 2023
1 parent c9c4e4e commit 653cb21
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/Fields/Settings/FilterBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,43 @@

trait FilterBy
{
public function postTypes(array $postTypes): static
/**
* @param string[] $postStatus draft, future, pending, private, publish
* @throws \InvalidArgumentException
*/
public function postStatus(array|string $postStatus): static
{
$this->settings['post_type'] = $postTypes;
if (is_string($postStatus)) {
$postStatus = [$postStatus];
}

if (count(array_diff($postStatus, ['draft', 'future', 'pending', 'private', 'publish'])) > 0) {
throw new InvalidArgumentException('Invalid argument post status.');
}

$this->settings['post_status'] = $postStatus;

return $this;
}

public function taxonomies(array $taxonomies): static
public function postTypes(array|string $postTypes): static
{
$this->settings['taxonomy'] = $taxonomies;
if (is_string($postTypes)) {
$postTypes = [$postTypes];
}

$this->settings['post_type'] = $postTypes;

return $this;
}

/**
* @param string[] $postStatus draft, future, pending, private, publish
* @throws \InvalidArgumentException
*/
public function postStatus(array $postStatus): static
public function taxonomies(array $taxonomies): static
{
if (count(array_diff($postStatus, ['draft', 'future', 'pending', 'private', 'publish'])) > 0) {
throw new InvalidArgumentException('Invalid argument post status.');
if (is_string($taxonomies)) {
$taxonomies = [$taxonomies];
}

$this->settings['post_status'] = $postStatus;
$this->settings['taxonomy'] = $taxonomies;

return $this;
}
Expand Down

0 comments on commit 653cb21

Please sign in to comment.