PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.9
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.9
7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / views / admin / commons / options.php
wordpress-popup / views / admin / commons Last commit date
sui-listing 9 months ago sui-wizard 9 months ago wizard 3 years ago modal-template.php 3 years ago options.php 3 years ago pagination.php 3 years ago view-documentation.php 5 years ago
options.php
438 lines
1 <?php
2 /**
3 * Templates for different field types and elements.
4 * Markup for us, frontend dummies.
5 * These are the variables that are used in most of the elements this file:
6 *
7 * $type string The field/element type.
8 * select|checkboxes|checkbox|{anything else as a regular input}
9 * $is_template bool Whether the field is used in an underscore template. Default: false.
10 * $id string ID property of the field.
11 * $class string Classes of the field.
12 * $name string Name of the field. For $is_template, it should
13 * have the same name as the js property that contains its value.
14 * $attributes array Associative array with other properties for the field. @see Hustle_Layout_Helper::render_attributes().
15 *
16 *
17 * $options array Set of options for rendering the element. Used by select|checkboxes|side_tabs.
18 * For select and checkboxes, it's an associative array where the key of the pair is the
19 * option's "value" property, and the value of the pair is the displayed label of the option. .
20 * For side_tabs, read more on the element's section.
21 *
22 * $selected string Used only if ! $is_template. The current stored value of the field. Must match the
23 * |array 'key' of its respective option pair in the $options array.
24 * Used by select|checkboxes|checkbox|checkbox_toggle|side_tabs.
25 *
26 *
27 * $value string Value of the field.
28 * Make sure it's properly escaped when rendering 'inline_notice'.
29 *
30 * $label string Label for the input. Used by checkbox|checkbox_toggle.
31 * $description string Description for the input. Used by checkbox|checkbox_toggle.
32 *
33 * $placeholder string TO BE DEPRECATED favoring accessibility. Placeholder of the field.
34 * $icon string Name of the icon as per SUI names. Used by text|number.
35 * $icon_position string Whether the icon goes before or after the input. Allowed values: before|after.
36 *
37 * $elements array Array with the options to render withing the wrapper. Used by wrapper.
38 *
39 * $tag string Tag name for inline HTML elements. Used by inline_element.
40 *
41 * NOTE: enable phpcs when editing stuff. Make sure what's left is okay. Disable it again afterwards.
42 *
43 * @package Hustle
44 * @since 4.2.0
45 */
46
47 // Flag for when the option is used in underscore template files.
48 $is_template = isset( $is_template ) ? $is_template : false;
49 $attributes = isset( $attributes ) ? $attributes : array();
50
51 $label_attributes = isset( $label_attributes ) ? $label_attributes : array();
52
53 switch ( $type ) :
54
55 // ELEMENT: Wrapper div.
56 case 'wrapper':
57 ?>
58 <div
59 <?php echo empty( $id ) ? '' : 'id="' . esc_attr( $id ) . '"'; ?>
60 <?php echo empty( $class ) ? '' : 'class="' . esc_attr( $class ) . '"'; ?>
61 <?php $this->render_attributes( $attributes ); ?>
62 >
63 <?php
64 foreach ( $elements as $element ) {
65 $this->render( 'admin/commons/options', $element );
66 }
67 ?>
68 </div>
69
70 <?php
71 break;
72
73 // ELEMENT: Select.
74 case 'select':
75 if ( self::$dont_init_selects &&
76 0 !== strpos( $name, 'custom_height_unit' ) && 0 !== strpos( $name, 'custom_width_unit' ) ) {
77 $new_class = ' none-sui';
78 $class = empty( $class ) ? $new_class : $class . $new_class;
79 }
80 ?>
81 <select
82 id="<?php echo empty( $id ) ? 'hustle-select-' . esc_attr( $name ) : esc_attr( $id ); ?>"
83 name="<?php echo esc_attr( $name ); ?>"
84 <?php echo empty( $class ) ? '' : 'class="' . esc_attr( $class ) . '"'; ?>
85 <?php echo empty( $placeholder ) ? '' : 'data-placeholder="' . esc_attr( $placeholder ) . '"'; ?>
86 <?php $this->render_attributes( $attributes ); ?>
87 tabindex="-1"
88 aria-hidden="true"
89 >
90
91 <?php if ( ! empty( $placeholder ) ) : ?>
92 <option></option>
93 <?php
94 endif;
95
96 // Fully server's side rendered field.
97 if ( ! $is_template ) :
98
99 foreach ( $options as $value => $label ) :
100 $label = ! empty( $label ) ? $label : '&#8205;';
101 $_selected = is_array( $selected ) && empty( $selected ) ? '' : $selected;
102 ?>
103 <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $_selected, $value ); ?>>
104 <?php echo esc_html( $label ); ?>
105 </option>
106 <?php
107 endforeach;
108
109 else :
110
111 foreach ( $options as $value => $label ) :
112 ?>
113 <option value="<?php echo esc_attr( $value ); ?>" {{ _.selected( <?php echo esc_attr( $name ); ?>, '<?php echo esc_attr( $value ); ?>' ) }}>
114 <?php echo esc_html( $label ); ?>
115 </option>
116 <?php
117 endforeach;
118
119 endif;
120 ?>
121
122 </select>
123
124 <?php
125 break;
126
127 // ELEMENT: Multiple checkboxes.
128 case 'checkboxes':
129 // Fully server's side rendered field.
130 if ( ! $is_template ) :
131
132 $_selected = isset( $selected ) ? $selected : array();
133 if ( ! is_array( $_selected ) ) {
134 $_selected = array( $_selected );
135 }
136
137 foreach ( $options as $value => $label ) :
138 ?>
139
140 <label class="sui-checkbox <?php echo isset( $class ) ? esc_attr( $class ) : ''; ?>">
141
142 <input
143 type="checkbox"
144 name="<?php echo esc_attr( $name ); ?>"
145 value="<?php echo esc_attr( $value ); ?>"
146 <?php echo isset( $id ) ? 'id="' . esc_attr( $id . '-' . $value ) . '"' : ''; ?>
147 <?php $this->render_attributes( $attributes ); ?>
148 <?php checked( in_array( $value, $_selected, true ) ); ?>
149 />
150
151 <span aria-hidden="true"></span>
152
153 <span><?php echo esc_html( $label ); ?></span>
154
155 </label>
156
157 <?php
158 endforeach;
159
160 else : // Field expecting parameters from underscore templating.
161
162 foreach ( $options as $value => $label ) :
163 ?>
164
165 <label class="sui-checkbox <?php echo isset( $class ) ? esc_attr( $class ) : ''; ?>">
166
167 <input
168 type="checkbox"
169 name="<?php echo esc_attr( $name ); ?>"
170 value="<?php echo esc_attr( $value ); ?>"
171 <?php echo isset( $id ) ? 'id="' . esc_attr( $id . '-' . $value ) . '"' : ''; ?>
172 <?php $this->render_attributes( $attributes ); ?>
173 {{ _.checked( <?php echo esc_attr( $name ); ?>.includes( '<?php echo esc_attr( $value ); ?>' ), true ) }}
174 />
175
176 <span aria-hidden="true"></span>
177 <span><?php echo esc_html( $label ); ?></span>
178
179 </label>
180
181 <?php
182 endforeach;
183
184 endif;
185 break;
186
187 // ELEMENT: Checkbox.
188 case 'checkbox':
189 $selected_value = isset( $value ) ? $value : '1';
190 ?>
191
192 <label class="sui-checkbox <?php echo isset( $class ) ? esc_attr( $class ) : ''; ?>" <?php $this->render_attributes( $label_attributes ); ?>>
193
194 <input
195 type="checkbox"
196 name="<?php echo esc_attr( $name ); ?>"
197 <?php echo isset( $value ) ? 'value="' . esc_attr( $value ) . '"' : ''; ?>
198 <?php echo isset( $id ) ? 'id="' . esc_attr( $id . '-' . $value ) . '"' : ''; ?>
199 aria-labelledby="hustle-checkbox-<?php echo esc_attr( $name ); ?>-label"
200 <?php echo empty( $description ) ? '' : 'aria-describedby="hustle-checkbox-' . esc_attr( $name ) . '-description"'; ?>
201 <?php $this->render_attributes( $attributes ); ?>
202 <?php
203 // If $value is not set, this is an on/off checkbox.
204 if ( ! $is_template ) {
205 checked( $selected_value, $selected );
206 } else {
207 echo '{{ _.checked( "' . esc_attr( $value ) . '", ' . esc_attr( $name ) . ' ) }}';
208 }
209 ?>
210 />
211 <span aria-hidden="true"></span>
212 <span id="hustle-checkbox-<?php echo esc_attr( $name ); ?>-label"><?php echo wp_kses_post( $label ); ?></span>
213
214 <?php if ( ! empty( $description ) ) : ?>
215 <span id="hustle-checkbox-<?php echo esc_attr( $name ); ?>-description" class="sui-description"><?php echo esc_html( $description ); ?></span>
216 <?php endif; ?>
217
218 </label>
219
220 <?php
221 break;
222
223 // ELEMENT: Toggle checkbox.
224 case 'checkbox_toggle':
225 ?>
226
227 <label
228 class="sui-toggle <?php echo isset( $class ) ? esc_attr( $class ) : ''; ?>"
229 <?php echo empty( $id ) ? '' : 'id="' . esc_attr( $id ) . '"'; ?>
230 <?php $this->render_attributes( $label_attributes ); ?>
231 >
232 <input
233 type="checkbox"
234 name="<?php echo esc_attr( $name ); ?>"
235 aria-labelledby="hustle-toggle-<?php echo esc_attr( $name ); ?>-label"
236 <?php echo empty( $value ) ? '' : 'value="' . esc_attr( $value ) . '"'; ?>
237 <?php echo empty( $description ) ? '' : 'aria-describedby="hustle-toggle-' . esc_attr( $name ) . '-description"'; ?>
238 <?php $this->render_attributes( $attributes ); ?>
239 <?php
240 if ( is_array( $selected ) ) {
241 checked( in_array( $value, $selected, true ) );
242 } else {
243 if ( ! $is_template ) {
244 checked( $value, $selected );
245 } else {
246 echo '{{ _.checked( "' . esc_attr( $value ) . '", ' . esc_attr( $name ) . ' ) }}';
247 }
248 }
249 ?>
250 />
251 <span class="sui-toggle-slider" aria-hidden="true"></span>
252
253 <span id="hustle-toggle-<?php echo esc_attr( $name ); ?>-label" class="sui-toggle-label"><?php echo esc_html( $label ); ?></span>
254
255 <?php if ( ! empty( $description ) ) : ?>
256 <span id="hustle-toggle-<?php echo esc_attr( $name ); ?>-description" class="sui-description"><?php echo esc_html( $description ); ?></span>
257 <?php endif; ?>
258 </label>
259
260 <?php
261 break;
262
263 case 'side_tabs':
264 /**
265 * $options is an array, containing another array for each tab.
266 * This is the structure for each tab's array:
267 *
268 * Array(
269 * 'value' => string Input's value.
270 * 'label' => string Tab's label.
271 * 'has_content' => bool Optional. Default: false. Whether the tab has dependent content.
272 * 'content_id' => string Optional. ID of the dependent content IF 'content_htlm' isn't provided.
273 * 'content_html' => string Optional. Markup for the dependent content. Skip if 'content_id' is provided.
274 * 'content_label' => string Optional. Screen reader label for the content when 'content_html' is specified.
275 * )
276 */
277 $tabs_attributes = empty( $tabs_attributes ) ? array() : $tabs_attributes;
278 ?>
279 <div class="sui-tabs sui-side-tabs <?php echo empty( $class ) ? '' : esc_attr( $class ); ?>">
280
281 <?php foreach ( $options as $data ) { ?>
282 <input
283 type="radio"
284 name="<?php echo esc_attr( $name ); ?>"
285 value="<?php echo esc_attr( $data['value'] ); ?>"
286 id="hustle-<?php echo esc_attr( $name ); ?>--<?php echo esc_attr( $data['value'] ); ?>"
287 class="sui-screen-reader-text hustle-tabs-option"
288 aria-hidden="true"
289 tabindex="-1"
290 <?php $this->render_attributes( $attributes ); ?>
291 <?php
292 if ( ! $is_template ) {
293 checked( $data['value'], $selected );
294 } else {
295 echo '{{ _.checked( "' . esc_attr( $data['value'] ) . '", ' . esc_attr( $name ) . ' ) }}';
296 }
297 ?>
298 />
299
300 <?php } ?>
301
302 <div role="tablist" class="sui-tabs-menu">
303
304 <?php foreach ( $options as $data ) { ?>
305 <?php
306 if ( $data['has_content'] ) {
307 $tab_content_id = ! empty( $data['content_id'] ) ? $data['content_id'] : 'tab-content-' . $name . '-' . $data['value'] . '-settings';
308 }
309 ?>
310
311 <button
312 role="tab"
313 type="button"
314 id="tab-<?php echo esc_attr( $name ); ?>--<?php echo esc_attr( $data['value'] ); ?>"
315 class="sui-tab-item"
316 data-label-for="hustle-<?php echo esc_attr( $name ); ?>--<?php echo esc_attr( $data['value'] ); ?>"
317 <?php echo empty( $tab_content_id ) ? '' : ' aria-controls="' . esc_attr( $tab_content_id ) . '"'; ?>
318 aria-selected="false"
319 tabindex="-1"
320 ><?php echo esc_html( $data['label'] ); ?></button>
321
322 <?php } ?>
323
324 </div>
325
326 <div class="sui-tabs-content">
327
328 <?php
329 foreach ( $options as $data ) :
330
331 if ( empty( $data['content_html'] ) || empty( $data['has_content'] ) ) {
332 continue;
333 }
334
335 $tab_content_id = ! empty( $data['content_id'] ) ? $data['content_id'] : 'tab-content-' . $name . '-' . $data['value'] . '-settings';
336 ?>
337 <div
338 role="tabpanel"
339 tabindex="-1"
340 id="<?php echo esc_attr( $tab_content_id ); ?>"
341 class="sui-tab-content"
342 aria-label="<?php echo esc_attr( $data['content_label'] ); ?>"
343 <?php $this->render_attributes( $tabs_attributes ); ?>
344 >
345 <?php echo wp_kses_post( $data['content_html'] ); ?>
346 </div>
347
348 <?php endforeach; ?>
349
350 </div>
351
352 </div>
353
354 <?php
355 break;
356
357 // ELEMENT: Simple inline element.
358 case 'inline_element':
359 ?>
360 <<?php echo esc_attr( $tag ); ?>
361 <?php echo empty( $id ) ? '' : 'id="' . esc_attr( $id ) . '"'; ?>
362 <?php echo empty( $class ) ? '' : 'class="' . esc_attr( $class ) . '"'; ?>
363 <?php $this->render_attributes( $attributes ); ?>
364 >
365 <?php echo wp_kses_post( $value ); ?>
366 </<?php echo esc_attr( $tag ); ?>>
367 <?php
368 break;
369
370 // ELEMENT: Inline notice.
371 case 'inline_notice':
372 // We're assuming that if there's no value, this is an inline alert notice, not a static one.
373 $is_alert = empty( $value );
374 ?>
375
376 <div
377 <?php echo ! $is_alert ? '' : 'role="alert" aria-live="assertive"'; ?>
378 <?php echo ! empty( $id ) ? 'id="' . esc_attr( $id ) . '"' : ''; ?>
379 class="sui-notice <?php echo isset( $class ) ? esc_attr( $class ) : ''; ?>"
380 <?php $this->render_attributes( $attributes ); ?>
381 >
382
383 <?php if ( ! $is_alert ) : ?>
384
385 <div class="sui-notice-content">
386
387 <div class="sui-notice-message">
388
389 <?php if ( ! empty( $icon ) ) : ?>
390 <span class="sui-notice-icon sui-icon-<?php echo esc_attr( $icon ); ?> sui-md" aria-hidden="true"></span>
391 <?php endif; ?>
392 <p><?php echo wp_kses_post( $value ); ?></p>
393
394 </div>
395
396 </div>
397
398 <?php endif; ?>
399
400 </div>
401
402 <?php
403 break;
404
405 // ELEMENT: Simple input.
406 default:
407 $_value = ! $is_template ? $value : '{{' . $name . '}}';
408
409 if ( isset( $icon ) ) :
410 ?>
411 <div class="sui-control-with-icon">
412 <?php if ( 'before' === $icon_position ) : ?>
413 <span class="sui-icon-<?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span>
414 <?php endif; ?>
415 <?php endif; ?>
416
417 <input
418 type="<?php echo esc_attr( $type ); ?>"
419 name="<?php echo esc_attr( $name ); ?>"
420 value="<?php echo esc_attr( $_value ); ?>"
421 <?php echo ( 'number' === $type && isset( $min ) && '' !== $min ) ? 'min="' . esc_attr( $min ) . '"' : ''; ?>
422 <?php echo ( 'number' === $type && isset( $max ) && '' !== $max ) ? 'max="' . esc_attr( $max ) . '"' : ''; ?>
423 class="sui-form-control<?php echo isset( $class ) ? ' ' . esc_attr( $class ) : ''; ?>"
424 <?php $this->render_attributes( $attributes ); ?>
425 <?php echo isset( $id ) ? 'id="' . esc_attr( $id ) . '"' : ''; ?>
426 <?php echo isset( $placeholder ) ? 'placeholder="' . esc_attr( $placeholder ) . '"' : ''; ?>
427 />
428
429 <?php if ( isset( $icon ) ) : ?>
430 <?php if ( 'after' === $icon_position ) : ?>
431 <i class="sui-icon-<?php echo esc_attr( $icon ); ?>" aria-hidden="true"></i>
432 <?php endif; ?>
433 </div>
434 <?php endif; ?>
435
436 <?php
437 endswitch;
438