/** * Display a <select> dropdown element * * @param array $setting See `do_settings_field()`. Has been filtered through `RO3::get_field_array()` * @return null * @since 1.0.0 */ public static function select_field($setting) { extract($setting); ?> <select id="<?php echo $name; ?> " name="ro3_options[<?php echo $name; ?> ]" <?php if (isset($class)) { echo "class='{$class}'"; } ?> <?php if (array_key_exists('data', $setting)) { foreach ($setting['data'] as $k => $v) { echo " data-{$k}='{$v}'"; } } ?> > <?php # if we are given a string for $choices (i.e. single choice) if (is_string($choices)) { ?> <option value="<?php echo RO3::clean_str_for_field($choices); ?> " <?php selected(RO3_Options::$options[$name], RO3::clean_str_for_field($choice)); ?> ><?php echo $choices; ?> </option> <?php } elseif (is_array($choices)) { foreach ($choices as $choice) { # if $choice is a string if (is_string($choice)) { $label = $choice; $value = RO3::clean_str_for_field($choice); } elseif (is_array($choice)) { $label = $choice['label']; $value = isset($choice['value']) ? $choice['value'] : RO3::clean_str_for_field($choice['label']); } ?> <option value="<?php echo $value; ?> " <?php if (isset(RO3_Options::$options[$name])) { selected(RO3_Options::$options[$name], $value); } ?> ><?php echo $label; ?> </option> <?php } # end foreach: $choices } # endif: $choices is an array ?> </select><?php }