Skip to content

Commit

Permalink
Add support for 'exclude' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
raideus committed Oct 21, 2013
1 parent fb46526 commit 459527c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions wpas-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
private $values;
private $selected = '';
private $selected_r = array();
private $exclude = array();

function __construct($id, $args = array()) {
$defaults = array( 'label' => '',
Expand Down Expand Up @@ -64,6 +65,15 @@ function __construct($id, $args = array()) {
$this->selected_r = explode(',',$this->selected);
}

// Set excluded values
if (isset($exclude)) {
if (is_array($exclude)) {
$this->exclude = $exclude;
} else {
$this->exclude[] = $exclude;
}
}

}

function build_field() {
Expand Down Expand Up @@ -123,6 +133,7 @@ function select($multi = false) {
$output .= '"'.$multiple.'>';

foreach ($this->values as $value => $label) {
if (in_array($value,$this->exclude)) continue;
$value = esc_attr($value);
$label = esc_attr($label);
$output .= '<option value="'.$value.'"';
Expand All @@ -142,6 +153,7 @@ function checkbox() {
$output = '<div class="wpas-'.$this->id.'-checkboxes wpas-checkboxes field-container">';
$ctr = 1;
foreach ($this->values as $value => $label) {
if (in_array($value,$this->exclude)) continue;
$value = esc_attr($value);
$label = esc_attr($label);
$output .= '<div class="wpas-'.$this->id.'-checkbox-'.$ctr.'-container wpas-'.$this->id.'-checkbox-container wpas-checkbox-container">';
Expand All @@ -161,6 +173,7 @@ function radio() {
$output = '<div class="wpas-'.$this->id.'-radio-buttons wpas-radio-buttons field-container">';
$ctr = 1;
foreach ($this->values as $value => $label) {
if (in_array($value,$this->exclude)) continue;
$value = esc_attr($value);
$label = esc_attr($label);
$output .= '<div class="wpas-'.$this->id.'-radio-'.$ctr.'-container wpas-'.$this->id.'-radio-container wpas-radio-container">';
Expand Down

0 comments on commit 459527c

Please sign in to comment.