PluginProbe
Float menu – awesome floating side menu / 6.1
Float menu – awesome floating side menu v6.1
7.2.5 trunk 2.1 2.2 3.0.1 3.1 3.2.2 3.3.1 3.5 3.5.1 3.5.2 3.5.3. 3.5.4 4.0 4.1 4.1.1 4.2 4.3 4.3.1 4.3.2 5.0 5.0.1 5.0.2 5.0.3 5.1 All 57 releases
← All changes | classes/Admin/CreateFields.php +49 -72 trunk6.1 View file →
@@ -1,6 +1,17 @@
1 1 <?php
2 2
3 +/**
4 + * Class CreateFields
5 + *
6 + * @package WowPlugin
7 + * @subpackage Admin
8 + * @author Dmytro Lobov <dev@wow-company.com>, Wow-Company
9 + * @copyright 2024 Dmytro Lobov
10 + * @license GPL-2.0+
11 + *
12 + */
13 +
3 14 namespace FloatMenuLite\Admin;
4 15
5 16 class CreateFields {
6 17 /**
@@ -28,18 +39,14 @@
28 39 }
29 40 $args = $this->page_options[ $name ];
30 41 $key = $this->get_key( $name );
31 42 $data_field = $name;
32 -
33 - $opt_val = $args['val'] ?? $args['value'] ?? '';
34 - $default = $opt_val;
35 -
36 - if (empty($this->options['tool_id'])) {
37 - $default = $opt_val;
43 + $default = $args['val'] ?? '';
44 + if ( empty( $this->options['tool_id'] ) ) {
45 + $default = $args['val'] ?? '';
38 46 }
39 -
40 - $opt_key = $this->get_opt_key( $name );
41 - $value = $this->get_the_value( $name, $default );
47 + $opt_key = $this->get_opt_key( $name );
48 + $value = $this->get_the_value( $name, $default );
42 49 $class = ! empty( $args['class'] ) ? ' ' . $args['class'] : '';
43 50 $type = $args['type'] ?? 'text';
44 51 $label_class = isset( $args['label'] ) ? '' : 'screen-reader-text';
45 52 $label = ! empty( $args['label'] ) ? $args['label'] : '';
@@ -55,8 +62,9 @@
55 62 $template .= '</div>';
56 63 } else {
57 64 $template .= $this->get_template( $args );
58 65 }
66 +
59 67 $template .= '</div>';
60 68
61 69 $content = str_replace( [
62 70 '{{class}}',
@@ -73,9 +81,9 @@
73 81 ], [
74 82 $class,
75 83 esc_attr( $type ),
76 84 esc_attr( $key ),
77 - $value,
85 + esc_attr( $value ),
78 86 $atts,
79 87 esc_attr( $label_class ),
80 88 esc_html( $label ),
81 89 $addon,
@@ -89,10 +97,15 @@
89 97 return true;
90 98 }
91 99
92 100 private function output( $content ): void {
93 - $allowed_post_tags = wp_kses_allowed_html( 'post' );
94 - $allowed_html = array(
101 + $allowed_html = array(
102 + 'label' => array(
103 + 'class' => [],
104 + ),
105 + 'span' => array(
106 + 'class' => [],
107 + ),
95 108 'input' => array(
96 109 'type' => [],
97 110 'data-field' => [],
98 111 'name' => [],
@@ -107,13 +120,18 @@
107 120 'step' => [],
108 121 'data-alpha-enabled' => [],
109 122 ),
110 123 'textarea' => [
124 + 'name' => [],
125 + 'value' => [],
111 126 'placeholder' => [],
112 127 'data-field' => [],
113 - 'name' => [],
114 128 'class' => [],
115 129 ],
130 + 'div' => [
131 + 'data-field-box' => [],
132 + 'class' => []
133 + ],
116 134 'select' => [
117 135 'name' => [],
118 136 'data-field' => [],
119 137
@@ -124,18 +142,12 @@
124 142 ],
125 143 'optgroup' => [
126 144 'label' => [],
127 145 ],
128 - 'div' => [
129 - 'class' => [],
130 - 'data-field-box' => [],
131 - ],
132 146
133 147 );
134 - $allowed_post_tags[] = $allowed_html;
135 - $merged_allowed_tags = array_merge( $allowed_post_tags, $allowed_html );
136 148
137 - echo wp_kses( $content, $merged_allowed_tags );
149 + echo wp_kses( $content, $allowed_html );
138 150 }
139 151
140 152 private function get_template( $args ): string {
141 153 if ( $args['type'] === 'select' ) {
@@ -149,12 +161,8 @@
149 161 if ( $args['type'] === 'textarea' ) {
150 162 return $this->textarea_template();
151 163 }
152 164
153 - if ( $args['type'] === 'editor' ) {
154 - return $this->editor_template();
155 - }
156 -
157 165 return $this->text_template();
158 166 }
159 167
160 168 private function get_title( $args ) {
@@ -162,16 +170,9 @@
162 170 return '';
163 171 }
164 172
165 173 if ( is_string( $args['title'] ) ) {
166 - $title = '<div class="wpie-field__title">';
167 - $title .= esc_html( $args['title'] );
168 - if ( isset( $args['tooltip'] ) ) {
169 - $title .= '<sup class="has-tooltip wpie-color-dark" data-tooltip="' . esc_attr( $args['tooltip'] ) . '">ℹ</sup>';
170 - }
171 - $title .= '</div>';
172 -
173 - return $title;
174 + return '<div class="wpie-field__title">' . esc_html( $args['title'] ) . '</div>';
174 175 }
175 176
176 177 if ( is_array( $args['title'] ) ) {
177 178 return $this->get_checkbox_title( $args['title'] );
@@ -183,15 +184,12 @@
183 184 private function get_checkbox_title( $args ) {
184 185 $key = $this->get_key( $args['name'] );
185 186 $data_field = $args['name'] ?? 'wpie-field';
186 187
187 - $opt_val = $args['val'] ?? $args['value'] ?? '';
188 - $default = $opt_val;
189 -
190 - if (empty($this->options['tool_id'])) {
191 - $default = $opt_val;
188 + $default = $args['val'] ?? '';
189 + if ( empty( $this->options['id'] ) ) {
190 + $default = $args['val'] ?? '';
192 191 }
193 -
194 192 // $value = $this->options[ $key ] ?? $default;
195 193 $value = $this->get_the_value( $args['name'], $default );
196 194 $label_class = isset( $args['label'] ) ? '' : 'screen-reader-text';
197 195 $label = ! empty( $args['label'] ) ? $args['label'] : '';
@@ -196,14 +194,13 @@
196 194 $label_class = isset( $args['label'] ) ? '' : 'screen-reader-text';
197 195 $label = ! empty( $args['label'] ) ? $args['label'] : '';
198 196 $checked = checked( "1", $value, false );
199 197 $toogle = isset( $args['toggle'] ) ? ' has-checked' : '';
200 - $tooltip = isset( $args['tooltip'] ) ? '<sup class="has-tooltip wpie-color-dark" data-tooltip="' . esc_attr( $args['tooltip'] ) . '">ℹ</sup>' : '';
201 198 $template = '<div class="wpie-field__title' . esc_attr( $toogle ) . '">
202 199 <label class="wpie-field__title-label">
203 200 <input type="checkbox" data-field="{{data_field}}" {{checked}}>
204 201 <input type="hidden" name="{{name}}" value="' . esc_attr( $value ) . '">
205 - <span class="{{label_class}}">{{label}} {{tooltip}}</span></label></div>';
202 + <span class="{{label_class}}">{{label}}</span></label></div>';
206 203
207 204 return str_replace( [
208 205 '{{name}}',
209 206 '{{checked}}',
@@ -209,9 +206,8 @@
209 206 '{{checked}}',
210 207 '{{label_class}}',
211 208 '{{label}}',
212 209 '{{data_field}}',
213 - '{{tooltip}}',
214 210
215 211 ], [
216 212 esc_attr( $key ),
217 213 $checked,
@@ -216,10 +212,9 @@
216 212 esc_attr( $key ),
217 213 $checked,
218 214 esc_attr( $label_class ),
219 215 esc_html( $label ),
220 - $data_field,
221 - $tooltip
216 + $data_field
222 217
223 218 ], $template );
224 219 }
225 220
@@ -245,11 +240,11 @@
245 240 $label = ! empty( $args['label'] ) ? $args['label'] : '';
246 241 $key = $this->get_key( $args['name'] );
247 242 $data_field = $args['name'] ?? 'wpie-field';
248 243 $default = $args['val'] ?? '';
249 - $value = $this->get_the_value( $args['name'], $default );
250 - $atts = $this->get_attributes( $args, $value );
251 - $template = '<label class="wpie-field__label">
244 + $value = $this->get_the_value( $args['name'], $default );
245 + $atts = $this->get_attributes( $args, $value );
246 + $template = '<label class="wpie-field__label">
252 247 <span class="{{label_class}}">{{label}}</span>
253 248 <select name="{{name}}" data-field="{{data_field}}">
254 249 {{atts}}
255 250 </select>
@@ -273,16 +268,14 @@
273 268 }
274 269
275 270
276 271 private function get_attributes( $args, $value ) {
277 - $arr = $args['atts'] ?? $args['options'] ?? '';
278 -
279 - if (empty($arr) || !is_array($arr)) {
272 + if ( empty( $args['atts'] ) || ! is_array( $args['atts'] ) ) {
280 273 return false;
281 274 }
282 275 $atts = '';
283 276
284 - foreach ($arr as $key => $val) {
277 + foreach ( $args['atts'] as $key => $val ) {
285 278 if ( $args['type'] === 'select' ) {
286 279 if ( strrpos( $key, '_start' ) ) {
287 280 $atts .= '<optgroup label="' . esc_attr( $val ) . '">';
288 281 } elseif ( strrpos( $key, '_end' ) ) {
@@ -287,9 +280,10 @@
287 280 $atts .= '<optgroup label="' . esc_attr( $val ) . '">';
288 281 } elseif ( strrpos( $key, '_end' ) ) {
289 282 $atts .= '</optgroup>';
290 283 } else {
291 - $atts .= '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key,false ) . '>' . esc_html( $val ) . '</option>';
284 + $atts .= '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key,
285 + false ) . '>' . esc_html( $val ) . '</option>';
292 286 }
293 287 } else {
294 288 $atts .= ' ' . esc_attr( $key ) . '="' . esc_attr( $val ) . '"';
295 289 }
@@ -363,9 +357,9 @@
363 357 $parts = explode( '-', $name );
364 358 $arr_name = '';
365 359 foreach ( $parts as $partkey => $part ) {
366 360 if ( $partkey === 0 ) {
367 - $arr_name .= 'param[' . $part . ']';
361 + $arr_name .= $part;
368 362 continue;
369 363 }
370 364 $arr_name .= '[' . esc_attr( $part ) . ']';
371 365 }
@@ -373,24 +367,16 @@
373 367 }
374 368
375 369
376 370 if ( empty( $this->order ) ) {
377 - if ( strpos( $name, 'param[' ) !== false ) {
378 - return $name;
379 - }
380 -
381 - return 'param[' . $name . ']';
371 + return $name;
382 372 }
383 373
384 374 if ( ! is_array( $this->order ) ) {
385 - if ( strpos( $name, 'param[' ) !== false ) {
386 - return $name;
387 - }
388 -
389 - return 'param[' . $name . ']';
375 + return $name;
390 376 }
391 377
392 - $key = ( strpos( $name, 'param[' ) !== false ) ? $name : 'param[' . $name . ']';
378 + $key = $name;
393 379
394 380 foreach ( $this->order as $order ) {
395 381 if ( is_string( $order ) ) {
396 382 $key .= '[' . esc_attr( $order ) . ']';
@@ -436,16 +422,7 @@
436 422 <label class="wpie-field__label">
437 423 <textarea name="{{name}}" data-field="{{data_field}}" {{atts}}>{{value}}</textarea>
438 424 <span class="{{label_class}}">{{label}}</span>
439 425 </label>
440 - ';
441 - }
442 -
443 - private function editor_template(): string {
444 - return '
445 - <div class="wpie-field__label">
446 - <textarea name="{{name}}" data-field="{{data_field}}" {{atts}}>{{value}}</textarea>
447 - <span class="{{label_class}}">{{label}}</span>
448 - </div>
449 426 ';
450 427 }
451 428 }