IconPicker.php
1 year ago
Input.php
3 years ago
Select.php
4 years ago
Textarea.php
3 years ago
WPEditor.php
3 years ago
Select.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages\DragDropBuilder\Controls; |
| 4 | |
| 5 | |
| 6 | class Select |
| 7 | { |
| 8 | public $args; |
| 9 | |
| 10 | public function __construct($args) |
| 11 | { |
| 12 | $this->args = wp_parse_args( |
| 13 | $args, |
| 14 | ['name' => '', 'value' => '', 'options' => []] |
| 15 | ); |
| 16 | } |
| 17 | |
| 18 | public function render() |
| 19 | { |
| 20 | echo sprintf('<label for="%s" class="pp-label">%s</label>', esc_attr($this->args['name']), esc_attr($this->args['label'])); |
| 21 | |
| 22 | echo sprintf('<select class="pp-form-control" id="%1$s" name="%1$s">', esc_attr($this->args['name'])); |
| 23 | |
| 24 | foreach ($this->args['options'] as $key => $value) { |
| 25 | |
| 26 | $selected = sprintf( |
| 27 | "<# if(data.%s == '%s') { #> selected <# } #>", |
| 28 | esc_attr($this->args['name']), |
| 29 | esc_attr($key) |
| 30 | ); |
| 31 | |
| 32 | if (is_array($value)) { |
| 33 | echo "<optgroup label='" . esc_attr($key) . "'>"; |
| 34 | foreach ($value as $key2 => $value2) { |
| 35 | echo sprintf('<option value="%s" %s>%s</option>', esc_attr($key2), $selected, esc_attr($value2)); |
| 36 | } |
| 37 | echo '</optgroup>'; |
| 38 | } else { |
| 39 | echo sprintf('<option value="%s" %s>%s</option>', esc_attr($key), $selected, esc_attr($value)); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | echo '</select>'; |
| 44 | |
| 45 | if (isset($this->args['description'])) { |
| 46 | printf('<div class="pp-form-control-description">%s</div>', wp_kses_post($this->args['description'])); |
| 47 | } |
| 48 | } |
| 49 | } |