/** * Display a <select> dropdown element * @param array $setting See `do_settings_field()`. Has been filtered through `Alert_Bar::get_field_array()` * @since 1.0.0 */ public static function select_field($setting) { extract($setting); $val = self::get_option_value($setting); ?> <select id="<?php echo $name; ?> " name="<?php echo $setting['option_name']; ?> " <?php echo self::data_atts($setting); ?> <?php if (isset($class)) { echo "class='" . $class . "'"; } ?> > <?php foreach ($choices as $choice) { # if $choice is a string if (is_string($choice)) { $label = $choice; $value = Alert_Bar::clean_str_for_field($choice); } elseif (is_array($choice)) { $label = $choice['label']; $value = isset($choice['value']) ? $choice['value'] : Alert_Bar::clean_str_for_field($choice['label']); } ?> <option value="<?php echo $value; ?> " <?php if (array_key_exists('class', $choice)) { echo "class='" . $choice['class'] . "' "; } ?> <?php echo self::data_atts($choice); ?> <?php selected($val, $value); ?> ><?php echo $label; ?> </option> <?php } # end foreach: $choices ?> </select><?php }
extract($setting); if (!isset($choices)) { return; } $out = array(); if (!is_array($choices)) { $out[] = array('id' => $name . '_' . self::clean_str_for_field($choices), 'label' => $choices, 'value' => self::clean_str_for_field($choices)); } else { foreach ($choices as $choice) { if (!is_array($choice)) { $out[] = array('label' => $choice, 'id' => $name . '_' . self::clean_str_for_field($choice), 'value' => self::clean_str_for_field($choice)); } else { # if choice is already an array, we need to check for missing data if (!array_key_exists('id', $choice)) { $choice['id'] = $name . '_' . self::clean_str_for_field($choice['label']); } if (!array_key_exists('value', $choice)) { $choice['value'] = $name . '_' . self::clean_str_for_field($choice['label']); } $out[] = $choice; } } } return $out; } } # end class Alert_Bar # require files for plugin foreach (Alert_Bar::$classes as $class) { Alert_Bar::req_file(albar_dir("lib/class-{$class}.php")); }