PluginProbe
Hash Form – Drag & Drop Form Builder / trunk
Hash Form – Drag & Drop Form Builder vtrunk
1.4.4 1.4.3 1.4.2 1.4.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.6.1 1.2.7 1.2.8 1.2.9 1.3.0 All 47 releases
hash-form / includes / fields / HashFormFieldImageSelect.php

HashFormFieldImageSelect.php in Hash Form – Drag & Drop Form Builder trunk, at includes/fields/HashFormFieldImageSelect.php

77 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die();
3
4 class HashFormFieldImageSelect extends HashFormFieldType {
5
6 protected $type = 'image_select';
7
8 protected function field_settings_for_type() {
9 return array(
10 'default' => false,
11 'image_max_width' => true
12 );
13 }
14
15 protected function extra_field_default_opts() {
16 return array(
17 'image_id' => '',
18 'image_size' => '',
19 'select_option_type' => 'radio',
20 'options_layout' => 'inline',
21 'image_max_width' => '',
22 'image_max_width_unit' => '%',
23 );
24 }
25
26 private function get_url($image_id) {
27 $image_id = (int) $image_id;
28 $src = wp_get_attachment_image_src($image_id, 'full');
29 $url = is_array($src) ? $src[0] : '';
30 if (!$url) {
31 $url = wp_get_attachment_image_url($image_id);
32 }
33 return $url ? $url : '';
34 }
35
36 protected function input_html() {
37 $field = $this->get_field();
38
39 $options = $field['options'] ? $field['options'] : array();
40 $default = $field['default_value'] ? $field['default_value'] : array();
41 // A field saved before this option existed has no key for it.
42 $field_type = isset($field['select_option_type']) ? $field['select_option_type'] : '';
43 ?>
44
45 <div class="hf-choice-container">
46 <?php
47 foreach ($options as $option_key => $option) {
48 $label = isset($option['label']) ? $option['label'] : '';
49 ?>
50 <div class="hf-choice hf-<?php echo esc_attr($field_type); ?>">
51 <label for="<?php echo esc_attr($this->html_id('-' . $option_key)); ?>">
52 <input type="<?php echo esc_attr($field_type); ?>" name="<?php echo esc_attr($this->html_name()) . '[]'; ?>" id="<?php echo esc_attr($this->html_id('-' . $option_key)); ?>" value="<?php echo esc_attr($label); ?>" <?php checked(in_array($label, $default), true); ?>>
53 <div class="hf-field-is-container hf-field-is-has-label">
54 <div class="hf-field-is-image">
55 <span class="hf-field-is-checked mdi-check-circle"></span>
56 <?php
57 if (isset($option['image_id']) && $option['image_id']) {
58 ?>
59 <img src="<?php echo esc_url($this->get_url($option['image_id'])); ?>" alt="<?php echo esc_attr($label); ?>">
60 <?php
61 }
62 ?>
63 </div>
64 <div class="hf-field-is-label"><?php echo esc_html($label); ?></div>
65 </div>
66 </label>
67 </div>
68 <?php
69 }
70 ?>
71
72 </div>
73 <?php
74 }
75
76 }
77