Skip to content

Commit

Permalink
bugfix for radio fields * add filter for WP_Query vars which only all…
Browse files Browse the repository at this point in the history
…ow scalar values
  • Loading branch information
raideus committed Jun 30, 2015
1 parent 8e7051a commit 91db44a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/AjaxConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion src/InputMarkup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '</div>';
return $output;
}
Expand Down Expand Up @@ -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 type="'.$type.'" id="wpas-'.$id.'-'.$type.'-'.$ctr.'" class="wpas-'.$id.'-'.$type.' wpas-'.$type.' '.$this->input->getClass().'" name="'.$this->input->getInputName().'[]" value="'.$value.'"';
. '<input type="'.$type.'" id="wpas-'.$id.'-'.$type.'-'.$ctr.'" class="wpas-'.$id.'-'.$type.' wpas-'.$type.' '.$this->input->getClass().'" name="'.$name.'" value="'.$value.'"';
if (in_array($value, $this->input->getSelected(), true)) {
$output .= ' checked="checked"';
}
Expand Down
21 changes: 19 additions & 2 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 91db44a

Please sign in to comment.