From 91db44ab8a35228339f4cee877fae2620e439267 Mon Sep 17 00:00:00 2001 From: Sean Butze Date: Mon, 29 Jun 2015 21:32:54 -0700 Subject: [PATCH] bugfix for radio fields * add filter for WP_Query vars which only allow scalar values --- src/AjaxConfig.php | 3 ++- src/InputMarkup.php | 5 ++++- src/Query.php | 21 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/AjaxConfig.php b/src/AjaxConfig.php index 01745dd..66e92e9 100644 --- a/src/AjaxConfig.php +++ b/src/AjaxConfig.php @@ -14,7 +14,8 @@ class AjaxConfig extends StdObject 'enabled' => 'bool', 'loading_img' => 'string', 'button_text' => 'string', - 'show_default_results' => 'bool' + 'show_default_results' => 'bool', + 'results_template' => 'string' ); static protected $defaults = array( diff --git a/src/InputMarkup.php b/src/InputMarkup.php index 88230c7..7f254b0 100644 --- a/src/InputMarkup.php +++ b/src/InputMarkup.php @@ -150,6 +150,7 @@ private function listField($is_checkbox = true) { foreach ($this->input->getValues() as $value => $label) { $output .= call_user_func(array($this,$option_func), $value, $label); } + $output .= ''; return $output; } @@ -351,8 +352,10 @@ private function listOption($value, $label, $type = 'checkbox') { $ctr = $this->ctr; $element = ($this->input->isNested()) ? 'li' : 'div'; $id = $this->input->getId(); + $name = $this->input->getInputName(); + $name .= ($type == 'checkbox') ? '[]' : ''; $output = '<'.$element.' class="wpas-'.$id.'-'.$type.'-'.$ctr.'-container wpas-'.$id.'-'.$type.'-container wpas-'.$type.'-container">' - . 'input->getSelected(), true)) { $output .= ' checked="checked"'; } diff --git a/src/Query.php b/src/Query.php index 77a25a4..29ec40e 100644 --- a/src/Query.php +++ b/src/Query.php @@ -11,6 +11,23 @@ class Query extends StdObject { private $orderby_meta_keys; private $query; + private static $filters = array( + 'search' => 'toScalar', + 'posts_per_page' => 'toScalar', + 'order' => 'toScalar' + ); + + private static function filter($query_var, $value) { + if (empty(self::$filters[$query_var])) return $value; + $func = self::$filters[$query_var]; + return call_user_func('self::'.$func,$value); + } + + private static function toScalar($value) { + if (is_array($value)) return reset($value); + return $value; + } + public function __construct(array $fields_table, array $wp_query_args, HttpRequest $request) { $this->wp_query_args = $wp_query_args; $this->fields = $fields_table; @@ -118,7 +135,7 @@ private function addOrderbyArg(array $query, HttpRequest $request) { private function addQueryArg(array $query, array $fields, HttpRequest $request) { if (empty($fields)) return $query; $field = reset($fields); // As of v1.4, only one field allowed per - // query var (other than taxonomy and meta_key) + // query var (other than taxonomy and meta_key) $field_id = $field->getFieldId(); $var = RequestVar::nameToVar($field_id); @@ -130,7 +147,7 @@ private function addQueryArg(array $query, array $fields, HttpRequest $request) if (empty($val)) return $query; - $query[$wp_var] = $val; + $query[$wp_var] = self::filter($wp_var,$val); return $query; }