From 0fcb0fa36f3ddf86b01ac84d96584ab0a1446a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 30 Nov 2023 15:10:56 +0100 Subject: [PATCH] Simplify QueryVars --- src/QueryVars.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/QueryVars.php b/src/QueryVars.php index 0eff276..c61cb1b 100644 --- a/src/QueryVars.php +++ b/src/QueryVars.php @@ -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) @@ -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']] + ); } }