Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify QueryVars #28

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/QueryVars.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace Outlandish\Wordpress\Oowp;

use WP_Query;

class QueryVars
{
private $args;

function __construct($data)
{
if ($data instanceof \WP_Query) {
$this->args = $data->query_vars;
} else {
$this->args = $data;
}
$this->args = $data instanceof WP_Query ? $data->query_vars : $data
}

public function hasArg($arg)
Expand All @@ -27,12 +25,9 @@ public function arg($arg)

public function isForPostType($postType)
{
$postTypes = $this->args['post_type'];
if (is_array($postTypes)) {
// TODO: Is this correct?
return in_array($postType, $postTypes);
} else {
return $postTypes == 'any' || $postTypes == $postType;
}
return in_array(
$postType,
is_array($this->args['post_type']) ? $this->args['post_type'] : ['any', $this->args['post_type']]
);
}
}