PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 5.1.1
Hustle – Email Marketing, Lead Generation, Optins, Popups v5.1.1
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 / lib / wpmu-lib / inc / class-thelib-html.php
wordpress-popup / lib / wpmu-lib / inc Last commit date
class-thelib-array.php 9 years ago class-thelib-core.php 9 years ago class-thelib-debug.php 9 years ago class-thelib-html.php 9 years ago class-thelib-net.php 9 years ago class-thelib-session.php 9 years ago class-thelib-ui.php 9 years ago class-thelib-updates.php 9 years ago class-thelib.php 9 years ago
class-thelib-html.php
1624 lines
1 <?php
2 /**
3 * HTML Helper functions
4 * Access via function `lib3()->html`.
5 *
6 * @since 1.1.0
7 */
8 class TheLib_Html extends TheLib {
9
10 /* Constants for default HTML input elements. */
11 const INPUT_TYPE_HIDDEN = 'hidden';
12 const INPUT_TYPE_TEXT_AREA = 'textarea';
13 const INPUT_TYPE_SELECT = 'select';
14 const INPUT_TYPE_RADIO = 'radio';
15 const INPUT_TYPE_SUBMIT = 'submit';
16 const INPUT_TYPE_BUTTON = 'button';
17 const INPUT_TYPE_CHECKBOX = 'checkbox';
18 const INPUT_TYPE_IMAGE = 'image';
19 // Different input types
20 const INPUT_TYPE_TEXT = 'text';
21 const INPUT_TYPE_PASSWORD = 'password';
22 const INPUT_TYPE_NUMBER = 'number';
23 const INPUT_TYPE_EMAIL = 'email';
24 const INPUT_TYPE_URL = 'url';
25 const INPUT_TYPE_TIME = 'time';
26 const INPUT_TYPE_SEARCH = 'search';
27 const INPUT_TYPE_FILE = 'file';
28
29 /* Constants for advanced HTML input elements. */
30 const INPUT_TYPE_WP_EDITOR = 'wp_editor';
31 const INPUT_TYPE_DATEPICKER = 'datepicker';
32 const INPUT_TYPE_RADIO_SLIDER = 'radio_slider';
33 const INPUT_TYPE_TAG_SELECT = 'tag_select';
34 const INPUT_TYPE_WP_PAGES = 'wp_pages';
35
36 /* Constants for default HTML elements. */
37 const TYPE_HTML_LINK = 'html_link';
38 const TYPE_HTML_SEPARATOR = 'html_separator';
39 const TYPE_HTML_TEXT = 'html_text';
40 const TYPE_HTML_TABLE = 'html_table';
41
42
43 /**
44 * Class constructor
45 *
46 * @since 1.1.0
47 */
48 public function __construct() {
49 parent::__construct();
50 }
51
52
53 /*================================*\
54 ====================================
55 == ==
56 == WP POINTER ==
57 == ==
58 ====================================
59 \*================================*/
60
61
62 /**
63 * Displays a WordPress pointer on the current admin screen.
64 *
65 * @since 1.1.0
66 * @api
67 *
68 * @param array|string $pointer_id Internal ID of the pointer, make sure it is unique!
69 * Optionally this param can contain all params in array notation.
70 * @param string $html_el HTML element to point to (e.g. '#menu-appearance')
71 * @param string $title The title of the pointer.
72 * @param string $body Text of the pointer.
73 *
74 * @return TheLib_Html Reference to $this for chaining.
75 */
76 public function pointer( $args, $html_el = '', $title = false, $body = '' ) {
77 if ( ! is_admin() ) {
78 return;
79 }
80
81 if ( is_array( $args ) ) {
82 if ( isset( $args['target'] ) && ! isset( $args['html_el'] ) ) {
83 $args['html_el'] = $args['target'];
84 }
85 if ( isset( $args['id'] ) && ! isset( $args['pointer_id'] ) ) {
86 $args['pointer_id'] = $args['id'];
87 }
88 if ( isset( $args['modal'] ) && ! isset( $args['blur'] ) ) {
89 $args['blur'] = $args['modal'];
90 }
91 if ( ! isset( $args['once'] ) ) {
92 $args['once'] = true;
93 }
94
95 self::$core->array->equip( $args, 'pointer_id', 'html_el', 'title', 'body', 'once', 'modal', 'blur' );
96
97 extract( $args );
98 } else {
99 $pointer_id = $args;
100 $once = true;
101 $modal = true;
102 $blur = true;
103 }
104
105 $once = self::$core->is_true( $once );
106 $modal = self::$core->is_true( $modal );
107 $blur = self::$core->is_true( $blur );
108
109 $this->_add( 'init_pointer', compact( 'pointer_id', 'html_el', 'title', 'body', 'once', 'modal', 'blur' ) );
110 $this->add_action( 'init', '_init_pointer' );
111
112 return $this;
113 }
114
115 /**
116 * Action handler for plugins_loaded. This decides if the pointer will be displayed.
117 *
118 * @since 1.0.2
119 * @internal
120 */
121 public function _init_pointer() {
122 $items = $this->_get( 'init_pointer' );
123 foreach ( $items as $item ) {
124 extract( $item ); // pointer_id, html_el, title, body, once, modal, blur
125 $show = true;
126
127 if ( $once ) {
128 // Find out which pointer IDs this user has already seen.
129 $seen = (string) get_user_meta(
130 get_current_user_id(),
131 'dismissed_wp_pointers',
132 true
133 );
134 $seen_list = explode( ',', $seen );
135 $show = ! in_array( $pointer_id, $seen_list );
136 } else {
137 $show = true;
138 }
139
140 // Include all scripts and code to display the pointer!
141 if ( $show ) {
142 $this->add_action( 'admin_print_footer_scripts', '_pointer_print_scripts' );
143 $this->add_action( 'admin_enqueue_scripts', '_enqueue_pointer' );
144
145 $this->_add( 'pointer', $item );
146 }
147 }
148 }
149
150 /**
151 * Enqueue wp-pointer
152 *
153 * @since 1.0.1
154 * @internal
155 */
156 public function _enqueue_pointer() {
157 // Load the JS/CSS for WP Pointers
158 wp_enqueue_script( 'wp-pointer' );
159 wp_enqueue_style( 'wp-pointer' );
160 }
161
162 /**
163 * Action hook for admin footer scripts
164 *
165 * @since 1.0.1
166 * @internal
167 */
168 public function _pointer_print_scripts() {
169 $items = $this->_get( 'pointer' );
170 foreach ( $items as $item ) {
171 extract( $item ); // pointer_id, html_el, title, body, once, modal, blur
172 include $this->_view_path( 'pointer.php' );
173 }
174 }
175
176
177 /*===========================*\
178 ===============================
179 == ==
180 == POPUP ==
181 == ==
182 ===============================
183 \*===========================*/
184
185
186 /**
187 * Display a wpmUi popup on page load.
188 *
189 * @since 1.1.0
190 * @api
191 *
192 * @param array $args Popup options.
193 * @return Reference to $this for chaining.
194 */
195 public function popup( $args = array() ) {
196 // Determine which hook should print the data.
197 $hook = ( is_admin() ? 'admin_footer' : 'wp_footer' );
198
199 self::$core->array->equip( $args, 'title', 'body', 'screen', 'modal', 'width', 'height', 'class' );
200
201 // Don't add empty popups
202 if ( empty( $args['title'] ) && empty( $args['body'] ) ) {
203 return;
204 }
205 if ( ! isset( $args['close'] ) ) {
206 $args['close'] = true;
207 }
208 if ( ! isset( $args['sticky'] ) ) {
209 $args['sticky'] = false;
210 }
211
212 $args['width'] = absint( $args['width'] );
213 $args['height'] = absint( $args['height'] );
214
215 if ( $args['width'] < 20 ) {
216 $args['width'] = -1;
217 }
218 if ( $args['height'] < 20 ) {
219 $args['height'] = -1;
220 }
221
222 $args['modal'] = $args['modal'] ? 'true' : 'false';
223 $args['persist'] = $args['sticky'] ? 'false' : 'true';
224 $args['close'] = $args['close'] ? 'true' : 'false';
225
226 self::_add( 'popup', $args );
227 $this->add_action( $hook, '_popup_callback' );
228 self::$core->ui->add( 'core' );
229
230 return $this;
231 }
232
233 /**
234 * Add popup code to the page footer
235 *
236 * @since 1.1.3
237 * @internal
238 */
239 public function _popup_callback() {
240 $items = self::_get( 'popup' );
241 self::_clear( 'popup' );
242 $screen_info = get_current_screen();
243 $screen_id = $screen_info->id;
244
245 foreach ( $items as $item ) {
246 extract( $item ); // title, body, modal, close, modal, persist, width, height, class
247
248 if ( empty( $title ) ) {
249 $close = false;
250 }
251
252 if ( empty( $screen ) || $screen_id == $screen ) {
253 $body = '<div>' . $body . '</div>';
254 echo '<script>jQuery(function(){wpmUi.popup()';
255 printf( '.title( %1$s, %2$s )', json_encode( $title ), $close );
256 printf( '.modal( %1$s, %2$s )', $modal, $persist );
257 printf( '.size( %1$s, %2$s )', json_encode( $width ), json_encode( $height ) );
258 printf( '.set_class( %1$s )', json_encode( $class ) );
259 printf( '.content( %1$s )', json_encode( $body ) );
260 echo '.show();})</script>';
261 }
262 }
263 }
264
265
266 /*=================================*\
267 =====================================
268 == ==
269 == PLUGIN LIST ==
270 == ==
271 =====================================
272 \*=================================*/
273
274
275 /**
276 * Generates full code for a plugin list in WordPress 4.0 style, including
277 * the filter and search section in the top.
278 *
279 * All items are included in page load and displayed or filtered via
280 * javascript.
281 *
282 * @since 1.1
283 * @api
284 *
285 * @param array $items {
286 * List of all items to include. Each item has these properties:
287 *
288 * @var string $title
289 * @var string $description
290 * @var string $version
291 * @var string $author
292 * @var array $action
293 * @var array $details
294 * @var bool $active
295 * @var string $icon
296 * }
297 * @param object $lang {
298 * @var string $active_badge
299 * @var string $show_details
300 * @var string $close_details
301 * }
302 * @param array $filters {
303 * @var string $key
304 * @var string $label
305 * }
306 *
307 * @return Reference to $this for chaining.
308 */
309 public function addon_list( $items, $lang, $filters ) {
310 self::$core->ui->css( $this->_css_url( 'wpmu-card-list.3.min.css' ) );
311 self::$core->ui->js( $this->_js_url( 'wpmu-card-list.3.min.js' ) );
312 include $this->_view_path( 'list.php' );
313 return $this;
314 }
315
316
317 /*====================================*\
318 ========================================
319 == ==
320 == HTML STRUCTURE ==
321 == ==
322 ========================================
323 \*====================================*/
324
325
326 /**
327 * Method for creating HTML elements/fields.
328 *
329 * Pass in array with field arguments. See $defaults for argmuments.
330 * Use constants to specify field type. e.g. self::INPUT_TYPE_TEXT
331 *
332 * @since 1.1.0
333 * @api
334 *
335 * @param array|string $field_args {
336 * If this param is a string then the string is output.
337 * Otherwise an array is expected that defines the output
338 * field.
339 *
340 * $type string Field type. {@see const definitions}
341 * $id string Field ID (html attribute)
342 * $class string Field class (html attribute)
343 * $value string Field value (html attribute)
344 *
345 * $title string Field label/caption to display.
346 * $desc string Description.
347 * $before string Text before the input element.
348 * $after string Text after the input element.
349 *
350 * (more attributes available)
351 * }
352 * @param bool $return Optional. If true the element is returned by
353 * function. Default: false (direct echo the HTML)
354 *
355 * @return void|string If $return param is false the HTML will be echo'ed,
356 * otherwise returned as string (default is echo)
357 */
358 public function element( $field_args, $return = false ) {
359 self::$core->ui->add( 'html_element' );
360
361 if ( is_string( $field_args ) ) {
362 if ( $return ) {
363 return $field_args;
364 } else {
365 echo $field_args;
366 return;
367 }
368 }
369
370 // Field arguments.
371 $defaults = array(
372 'id' => '',
373 'name' => '',
374 'section' => '', // Only used if name is empty
375 'title' => '', // Title above desc / element
376 'desc' => '', // Usually displayed in row above the element
377 'before' => '', // In same row as element
378 'after' => '', // In same row as element
379 'value' => '',
380 'type' => 'text',
381 'class' => '',
382 'label_class' => '',
383 'maxlength' => '',
384 'equalTo' => '',
385 'field_options' => array(),
386 'multiple' => false,
387 'tooltip' => '',
388 'alt' => '',
389 'read_only' => false,
390 'placeholder' => '',
391 'data_placeholder' => '',
392 'ajax_data' => '',
393 'data' => array(),
394 'label_type' => 'label',
395 'sticky' => false, // populate $value from $_REQUEST struct
396 'config' => array(), // other, element-specific configurations
397 'wrapper_class' => '', // class added to the outermost element wrapper
398 // Specific for type 'button', 'submit':
399 'button_value' => '',
400 'button_type' => '', // for display [empty/'submit'/'button']
401 // Specific for type 'tag_select':
402 'title_selected' => '',
403 'empty_text' => '',
404 'button_text' => '',
405 // Specific for type 'link':
406 'target' => '_self',
407 // Specific for type 'radio_slider':
408 'url' => '',
409 );
410
411 $field_args = wp_parse_args( $field_args, $defaults );
412 extract( $field_args );
413
414 if ( empty( $name ) ) {
415 if ( ! empty( $section ) ) {
416 $name = $section . "[$id]";
417 } else {
418 $name = $id;
419 }
420 }
421
422 // Input arguments
423
424 $attr_placeholder = '';
425 $attr_data_placeholder = '';
426
427 if ( '' !== $placeholder && false !== $placeholder ) {
428 $attr_placeholder = 'placeholder="' . esc_attr( $placeholder ) . '" ';
429 }
430
431 if ( '' !== $data_placeholder && false !== $data_placeholder ) {
432 $attr_data_placeholder = 'data-placeholder="' . esc_attr( $data_placeholder ) . '" ';
433 }
434
435 if ( ! empty( $data_ms ) && empty( $ajax_data ) ) {
436 $ajax_data = $data_ms;
437 }
438
439 if ( ! empty( $ajax_data ) ) {
440 if ( ! empty( $ajax_data['action'] )
441 && ( empty( $ajax_data['_wpnonce'] )
442 || true === $ajax_data['_wpnonce']
443 )
444 ) {
445 $ajax_data['_wpnonce'] = wp_create_nonce( $ajax_data['action'] );
446 }
447
448 $ajax_data = ' data-wpmui-ajax="' . esc_attr( json_encode( $ajax_data ) ) . '" ';
449 }
450
451 $max_attr = empty( $maxlength ) ? '' : 'maxlength="' . esc_attr( $maxlength ) . '" ';
452 $read_only = empty( $read_only ) ? '' : 'readonly="readonly" ';
453 $multiple = empty( $multiple ) ? '' : 'multiple="multiple" ';
454
455 $data_attr = '';
456 foreach ( $data as $data_key => $data_value ) {
457 $data_attr .= 'data-' . $data_key . '=' . json_encode( $data_value ) . ' ';
458 }
459 foreach ( $config as $conf_key => $conf_value ) {
460 $data_attr .= $conf_key . '=' . json_encode( $conf_value ) . ' ';
461 }
462
463 if ( ! empty( $ajax_data ) ) {
464 $class .= ' wpmui-ajax-update';
465 }
466
467 if ( $sticky ) {
468 $sticky_key = $name;
469 if ( '[]' == substr( $sticky_key, -2 ) ) {
470 $sticky_key = substr( $sticky_key, 0, -2 );
471 }
472
473 if ( isset( $_POST[$sticky_key] ) ) {
474 $value = $_POST[$sticky_key];
475 } elseif ( isset( $_GET[$sticky_key] ) ) {
476 $value = $_GET[$sticky_key];
477 }
478 }
479
480 $field_options = self::$core->array->get( $field_options );
481
482 $labels = (object) array(
483 'title' => $title,
484 'desc' => $desc,
485 'before' => $before,
486 'after' => $after,
487 'tooltip' => $tooltip,
488 'tooltip_code' => $this->tooltip( $tooltip, true ),
489 'id' => $id,
490 'class' => $label_class,
491 'label_type' => $label_type,
492 );
493
494 // Capture to output buffer
495 if ( $return ) { ob_start(); }
496
497 switch ( $type ) {
498 case self::INPUT_TYPE_HIDDEN:
499 $this->element_hidden(
500 $id,
501 $name,
502 $value,
503 $class
504 );
505 break;
506
507 case self::INPUT_TYPE_TEXT:
508 case self::INPUT_TYPE_PASSWORD:
509 case self::INPUT_TYPE_NUMBER:
510 case self::INPUT_TYPE_EMAIL:
511 case self::INPUT_TYPE_URL:
512 case self::INPUT_TYPE_TIME:
513 case self::INPUT_TYPE_SEARCH:
514 case self::INPUT_TYPE_FILE:
515 $this->element_input(
516 $labels,
517 $type,
518 $class,
519 $id,
520 $name,
521 $value,
522 $read_only . $max_attr . $attr_placeholder . $ajax_data . $data_attr,
523 $wrapper_class
524 );
525 break;
526
527 case self::INPUT_TYPE_DATEPICKER:
528 $this->element_datepicker(
529 $labels,
530 $class,
531 $id,
532 $name,
533 $value,
534 $max_attr . $attr_placeholder . $ajax_data . $data_attr,
535 $wrapper_class
536 );
537 break;
538
539 case self::INPUT_TYPE_TEXT_AREA:
540 $this->element_textarea(
541 $labels,
542 $class,
543 $id,
544 $name,
545 $value,
546 $read_only . $attr_placeholder . $ajax_data . $data_attr,
547 $wrapper_class
548 );
549 break;
550
551 case self::INPUT_TYPE_SELECT:
552 $this->element_select(
553 $labels,
554 $class,
555 $id,
556 $name,
557 $value,
558 $multiple . $read_only . $attr_data_placeholder . $ajax_data . $data_attr,
559 $field_options,
560 $wrapper_class
561 );
562 break;
563
564 case self::INPUT_TYPE_RADIO:
565 $this->element_radio(
566 $labels,
567 $class,
568 $id,
569 $name,
570 $value,
571 $ajax_data,
572 $field_options,
573 $wrapper_class
574 );
575 break;
576
577 case self::INPUT_TYPE_CHECKBOX:
578 $this->element_checkbox(
579 $labels,
580 $class,
581 $id,
582 $name,
583 $value,
584 $ajax_data . $data_attr,
585 $field_options,
586 $config
587 );
588 break;
589
590 case self::INPUT_TYPE_WP_EDITOR:
591 $this->element_wp_editor(
592 $labels,
593 $id,
594 $value,
595 $field_options
596 );
597 break;
598
599 case self::INPUT_TYPE_BUTTON:
600 case self::INPUT_TYPE_SUBMIT:
601 if ( empty( $button_type ) ) {
602 $button_type = $type;
603 }
604
605 if ( $button_type === self::INPUT_TYPE_SUBMIT ) {
606 $class .= ' wpmui-submit button-primary';
607 }
608
609 $this->element_button(
610 $labels,
611 $type,
612 $class,
613 $id,
614 $name,
615 $value,
616 $button_value,
617 $ajax_data . $data_attr
618 );
619 break;
620
621 case self::INPUT_TYPE_IMAGE:
622 $this->element_image(
623 $labels,
624 $class,
625 $id,
626 $name,
627 $value,
628 $alt,
629 $ajax_data . $data_attr
630 );
631 break;
632
633 case self::INPUT_TYPE_RADIO_SLIDER:
634 $this->element_radioslider(
635 $labels,
636 $class,
637 $id,
638 $name,
639 $value,
640 $url,
641 $read_only,
642 $ajax_data . $data_attr,
643 $field_options,
644 $wrapper_class
645 );
646 break;
647
648 case self::INPUT_TYPE_TAG_SELECT:
649 $this->element_tagselect(
650 $labels,
651 $class,
652 $id,
653 $name,
654 $value,
655 $field_options,
656 $multiple . $read_only . $attr_data_placeholder . $data_attr,
657 $ajax_data,
658 $empty_text,
659 $button_text,
660 $title_selected,
661 $wrapper_class
662 );
663 break;
664
665 case self::INPUT_TYPE_WP_PAGES:
666 $this->element_wp_pages(
667 $labels,
668 $class,
669 $id,
670 $name,
671 $value,
672 $multiple . $read_only . $attr_data_placeholder . $ajax_data . $data_attr,
673 $field_options,
674 $wrapper_class
675 );
676 break;
677
678 case self::TYPE_HTML_LINK:
679 $this->element_link(
680 $labels,
681 $class,
682 $id,
683 $value,
684 $url,
685 $ajax_data . $data_attr,
686 $target
687 );
688 break;
689
690 case self::TYPE_HTML_SEPARATOR:
691 $this->element_separator(
692 ($value !== 'vertical' ? 'horizontal' : 'vertical')
693 );
694 break;
695
696 case self::TYPE_HTML_TEXT:
697 $this->element_wrapper(
698 $labels,
699 $class,
700 $id,
701 $value,
702 'span',
703 $wrapper_class
704 );
705 break;
706
707 case self::TYPE_HTML_TABLE:
708 $this->element_table(
709 $labels,
710 $class,
711 $id,
712 $value,
713 $field_options,
714 $wrapper_class
715 );
716 break;
717 }
718
719 // Return the output buffer
720 if ( $return ) { return ob_get_clean(); }
721 }
722
723
724 /**
725 * Helper function used by `html_element`
726 *
727 * @since 1.1.0
728 * @internal
729 */
730 private function element_hidden( $id, $name, $value, $class ) {
731 printf(
732 '<input class="wpmui-field-input wpmui-hidden %4$s" type="hidden" id="%1$s" name="%2$s" value="%3$s" />',
733 esc_attr( $id ),
734 esc_attr( $name ),
735 esc_attr( $value ),
736 esc_attr( $class )
737 );
738 }
739
740 /**
741 * Helper function used by `html_element`
742 *
743 * @since 1.1.0
744 * @internal
745 */
746 private function element_input( $labels, $type, $class, $id, $name, $value, $attr, $wrapper_class ) {
747 $this->wrap_open( 'input', $class, 'span', $wrapper_class );
748 $this->element_label( $labels );
749
750 printf(
751 '<input class="wpmui-field-input wpmui-%1$s %2$s wpmui-input-%4$s" type="%1$s" id="%3$s" name="%4$s" value="%5$s" %6$s />',
752 esc_attr( $type ),
753 esc_attr( $class ),
754 esc_attr( $id ),
755 esc_attr( $name ),
756 esc_attr( $value ),
757 $attr
758 );
759
760 $this->element_hint( $labels );
761 $this->wrap_close();
762 }
763
764 /**
765 * Helper function used by `html_element`
766 *
767 * @since 1.1.0
768 * @internal
769 */
770 private function element_datepicker( $labels, $class, $id, $name, $value, $attr, $wrapper_class ) {
771 $this->wrap_open( 'datepicker', $class, 'span', $wrapper_class );
772 $this->element_label( $labels );
773
774 if ( ! empty( $value ) ) {
775 if ( ! preg_match( '/\d\d\d\d-\d\d-\d\d/', $value ) ) {
776 $value = date( 'Y-m-d', strtotime( $value ) );
777 }
778 }
779
780 printf(
781 '<span class="wpmui-field-input"><input class="wpmui-datepicker %1$s" type="text" id="%2$s" name="%3$s" value="%4$s" %5$s /><i class="wpmui-icon wpmui-fa wpmui-fa-calendar"></i></span>',
782 esc_attr( $class ),
783 esc_attr( $id ),
784 esc_attr( $name ),
785 esc_attr( $value ),
786 $attr
787 );
788
789 $this->element_hint( $labels );
790 $this->wrap_close();
791 }
792
793 /**
794 * Helper function used by `html_element`
795 *
796 * @since 1.1.0
797 * @internal
798 */
799 private function element_textarea( $labels, $class, $id, $name, $value, $attr, $wrapper_class ) {
800 $this->wrap_open( 'textarea', $class, 'span', $wrapper_class );
801 $this->element_label( $labels );
802
803 printf(
804 '<textarea class="wpmui-field-input wpmui-textarea %1$s" type="text" id="%2$s" name="%3$s" %5$s>%4$s</textarea>',
805 esc_attr( $class ),
806 esc_attr( $id ),
807 esc_attr( $name ),
808 esc_textarea( $value ),
809 $attr
810 );
811
812 $this->element_hint( $labels );
813 $this->wrap_close();
814 }
815
816 /**
817 * Helper function used by `html_element`
818 *
819 * @since 1.1.0
820 * @internal
821 */
822 private function element_select( $labels, $class, $id, $name, $value, $attr, $field_options, $wrapper_class ) {
823 $options = $this->select_options( $field_options, $value );
824
825 $this->wrap_open( 'select', $class, 'span', $wrapper_class );
826 $this->element_label( $labels );
827
828 printf(
829 '<select id="%1$s" class="wpmui-field-input wpmui-field-select %2$s" name="%3$s" %4$s>%5$s</select>',
830 esc_attr( $id ),
831 esc_attr( $class ),
832 esc_attr( $name ),
833 $attr,
834 $options
835 );
836
837 $this->element_hint( $labels );
838 $this->wrap_close();
839 }
840
841 /**
842 * Helper function used by `html_element`
843 *
844 * @since 1.1.0
845 * @internal
846 */
847 private function element_radio( $labels, $class, $id, $name, $value, $attr, $field_options, $wrapper_class ) {
848 $this->wrap_open( 'radio', $class, 'span', $wrapper_class );
849 $this->element_label( $labels );
850
851 foreach ( $field_options as $key => $option ) {
852 if ( is_array( $option ) ) {
853 self::$core->array->equip( $option, 'text', 'desc', 'disabled' );
854 $item_text = $option['text'];
855 $item_desc = $option['desc'];
856 $item_disabled = self::$core->is_true( $option['disabled'] );
857 } else {
858 $item_text = $option;
859 $item_desc = '';
860 $item_disabled = false;
861 }
862
863 $checked = checked( $value, $key, false );
864 $item_attr = $attr;
865 $item_class = $class;
866 if ( $item_disabled ) {
867 $item_attr .= ' disabled="disabled"';
868 $item_class .= ' disabled';
869 }
870 $radio_desc = '';
871
872 if ( ! empty( $item_desc ) ) {
873 $radio_desc = sprintf( '<div class="wpmui-input-description"><p>%1$s</p></div>', $item_desc );
874 }
875
876 printf(
877 '<div class="wpmui-radio-input-wrapper %1$s wpmui-%2$s"><label class="wpmui-field-label" for="%4$s_%2$s"><input class="wpmui-field-input wpmui-radio %1$s" type="radio" name="%3$s" id="%4$s_%2$s" value="%2$s" %5$s /><span class="wpmui-radio-caption">%6$s</span>%7$s</label></div>',
878 esc_attr( $item_class ),
879 esc_attr( $key ),
880 esc_attr( $name ),
881 esc_attr( $id ),
882 $item_attr . $checked,
883 $item_text,
884 $radio_desc
885 );
886 }
887
888 $this->element_hint( $labels );
889 $this->wrap_close();
890 }
891
892 /**
893 * Helper function used by `html_element`
894 *
895 * @since 1.1.0
896 * @internal
897 */
898 private function element_checkbox( $labels, $class, $id, $name, $value, $attr, $itemlist, $options ) {
899 $item_desc = '';
900 if ( ! empty( $labels->desc ) ) {
901 $item_desc = sprintf( '<div class="wpmui-field-description"><p>%1$s</p></div>', $labels->desc );
902 }
903 $listitems = array();
904
905 if ( ! empty( $itemlist ) ) {
906 // Multiple items in the checkbox list.
907 printf(
908 '<div class="wpmui-checkbox-title">%1$s %2$s</div><div class="wpmui-checkbox-list wpmui-field-input">%3$s',
909 $labels->title,
910 $labels->tooltip,
911 $item_desc
912 );
913 $item_desc = '';
914
915 if ( ! is_array( $value ) ) {
916 $value = array( $value );
917 }
918
919 foreach ( $itemlist as $key => $item ) {
920 $tmp_items = array();
921 if ( is_array( $item ) ) {
922 $tmp_items[] = array(
923 'name' => false,
924 'label' => $key,
925 'value' => false,
926 'parent' => true,
927 );
928 foreach ( $item as $sub_key => $sub_item ) {
929 $tmp_items[] = array(
930 'name' => $name . '[]',
931 'label' => $sub_item,
932 'value' => $sub_key,
933 'child' => true,
934 );
935 }
936 } else {
937 $tmp_items[] = array(
938 'name' => $name . '[]',
939 'label' => $item,
940 'value' => $key,
941 );
942 }
943
944 foreach ( $tmp_items as $tmp_item ) {
945 $item_label = sprintf(
946 '<div class="wpmui-checkbox-caption">%1$s</div>',
947 $tmp_item['label']
948 );
949
950 $tmp_item['label'] = $item_label;
951 $tmp_item['checked'] = checked( in_array( $tmp_item['value'], $value ), true, false );
952 $tmp_item['child'] = empty( $tmp_item['child'] ) ? false : true;
953 $tmp_item['parent'] = empty( $tmp_item['parent'] ) ? false : true;
954
955 $listitems[] = $tmp_item;
956 }
957 }
958 } else {
959 // Single checkbox item.
960 $item_label = '';
961 if ( empty( $options['checkbox_position'] )
962 || 'left' === $options['checkbox_position']
963 ) {
964 $item_label = sprintf(
965 '<div class="wpmui-checkbox-caption">%1$s %2$s</div>',
966 $labels->title,
967 $labels->tooltip
968 );
969 }
970
971 $listitems[] = array(
972 'name' => $name,
973 'label' => $item_label,
974 'checked' => checked( $value, true, false ),
975 'value' => 1,
976 'child' => false,
977 'parent' => false,
978 );
979 }
980
981 $is_group = false;
982 foreach ( $listitems as $item ) {
983 $item_class = $class;
984 if ( $item['parent'] ) {
985 $is_group = true;
986 echo '<div class="wpmui-group">';
987 $item_class .= ' wpmui-parent';
988 } elseif ( $item['child'] ) {
989 $is_group = true;
990 $item_class .= ' wpmui-child';
991 } elseif ( $is_group ) {
992 echo '</div>';
993 $is_group = false;
994 }
995
996 if ( empty( $item['name'] ) ) {
997 printf(
998 '<label class="wpmui-checkbox-wrapper wpmui-field-label wpmui-no-checkbox %1$s">%2$s %3$s</label>',
999 esc_attr( $item_class ),
1000 $item['label'],
1001 $item_desc
1002 );
1003 } else {
1004 printf(
1005 '<label class="wpmui-checkbox-wrapper wpmui-field-label %2$s"><input id="%1$s" class="wpmui-field-input wpmui-field-checkbox" type="checkbox" name="%3$s" value="%7$s" %4$s />%5$s %6$s</label>',
1006 esc_attr( $id ),
1007 esc_attr( $item_class ),
1008 esc_attr( $item['name'] ),
1009 $attr . $item['checked'],
1010 $item['label'],
1011 $item_desc,
1012 $item['value']
1013 );
1014 }
1015 }
1016
1017 $this->element_hint( $labels );
1018
1019 if ( ! empty( $itemlist ) ) {
1020 echo '</div>';
1021 }
1022 }
1023
1024 /**
1025 * Helper function used by `html_element`
1026 *
1027 * @since 1.1.0
1028 * @internal
1029 */
1030 private function element_wp_editor( $labels, $id, $value, $options ) {
1031 $this->element_label( $labels );
1032
1033 wp_editor( $value, $id, $options );
1034
1035 $this->element_hint( $labels );
1036 }
1037
1038 /**
1039 * Helper function used by `html_element`
1040 *
1041 * @since 1.1.0
1042 * @internal
1043 */
1044 private function element_button( $labels, $type, $class, $id, $name, $label, $value, $attr ) {
1045 $this->element_label( $labels );
1046
1047 printf(
1048 '<button class="wpmui-field-input button %1$s" type="%7$s" id="%2$s" name="%3$s" value="%6$s" %5$s>%4$s</button>',
1049 esc_attr( $class ),
1050 esc_attr( $id ),
1051 esc_attr( $name ),
1052 $label,
1053 $attr,
1054 $value,
1055 $type
1056 );
1057
1058 $this->element_hint( $labels );
1059 }
1060
1061 /**
1062 * Helper function used by `html_element`
1063 *
1064 * @since 1.1.0
1065 * @internal
1066 */
1067 private function element_image( $labels, $class, $id, $name, $value, $alt, $attr ) {
1068 $this->element_label( $labels );
1069
1070 printf(
1071 '<input type="image" class="wpmui-field-input wpmui-input-image %1$s" id="%2$s" name="%3$s" border="0" src="%4$s" alt="%5$s" %6$s/>',
1072 esc_attr( $class ),
1073 esc_attr( $id ),
1074 esc_attr( $name ),
1075 esc_url( $value ),
1076 esc_attr( $alt ),
1077 $attr
1078 );
1079
1080 $this->element_hint( $labels );
1081 }
1082
1083 /**
1084 * Helper function used by `html_element`
1085 *
1086 * @since 1.1.0
1087 * @internal
1088 */
1089 private function element_radioslider( $labels, $class, $id, $name, $state, $url, $read_only, $attr, $options, $wrapper_class ) {
1090 $options = self::$core->array->get( $options );
1091 if ( ! isset( $options['active'] ) ) { $options['active'] = true; }
1092 if ( ! isset( $options['inactive'] ) ) { $options['inactive'] = false; }
1093
1094 if ( $state ) { $value = $options['active']; }
1095 else { $value = $options['inactive']; }
1096
1097 $turned = ( $value ) ? 'on' : 'off';
1098
1099 $this->wrap_open( 'radio-slider', $class, 'span', $turned . ' ' . $wrapper_class );
1100 $this->element_label( $labels );
1101
1102 $attr .= ' data-states="' . esc_attr( json_encode( $options ) ) . '" ';
1103 $link_url = ! empty( $url ) ? '<a href="' . esc_url( $url ) . '"></a>' : '';
1104
1105 $attr_input = '';
1106 if ( ! $read_only ) {
1107 $attr_input = sprintf(
1108 '<input class="wpmui-field-input wpmui-hidden" type="hidden" id="%1$s" name="%2$s" value="%3$s" />',
1109 esc_attr( $id ),
1110 esc_attr( $name ),
1111 esc_attr( $value )
1112 );
1113 }
1114
1115 printf(
1116 '<div class="wpmui-radio-slider %1$s wpmui-slider-%5$s %7$s" %6$s>%8$s<div class="wpmui-toggle" %2$s>%3$s</div>%4$s%9$s</div>',
1117 esc_attr( $turned ),
1118 $attr,
1119 $link_url,
1120 $attr_input,
1121 esc_attr( $id ),
1122 $read_only,
1123 esc_attr( $class ),
1124 '<span class="before"></span>',
1125 '<span class="after"></span>'
1126 );
1127
1128 $this->element_hint( $labels );
1129 $this->wrap_close();
1130 }
1131
1132 /**
1133 * Helper function used by `html_element`
1134 *
1135 * @since 1.1.0
1136 * @internal
1137 */
1138 private function element_tagselect( $labels, $class, $id, $name, $value, $field_options, $attr, $ajax_data, $empty_text, $button_text, $title_selected, $wrapper_class ) {
1139 $labels->id = '_src_' . $id;
1140
1141 $this->wrap_open( 'tag-selector', $class, 'span', $wrapper_class );
1142 $this->element_label( $labels );
1143
1144 $options_selected = '';
1145 $options_available = '<option value=""></option>';
1146 if ( ! is_array( $value ) ) {
1147 $value = array( $value );
1148 }
1149
1150 if ( empty( $field_options ) ) {
1151 // No values available, display a note instead of the input elements.
1152 printf(
1153 '<div id="%1$s" class="wpmui-no-data wpmui-field-input %2$s">%3$s</div>',
1154 esc_attr( $id ),
1155 esc_attr( $class ),
1156 $empty_text
1157 );
1158 } else {
1159 // There are values to select or remove. Display the input elements.
1160 $options_selected .= $this->select_options( $field_options, $value );
1161 $options_available .= $this->select_options( $field_options, $value, 'taglist' );
1162
1163 $src_class = str_replace( 'wpmui-ajax-update', '', $class );
1164
1165 // First Select: The value selected here can be added to the tag-list.
1166 printf(
1167 '<select id="_src_%1$s" class="wpmui-field-input wpmui-tag-source %2$s" %4$s>%5$s</select>',
1168 esc_attr( $id ),
1169 esc_attr( $src_class ),
1170 esc_attr( $name ),
1171 $attr,
1172 $options_available
1173 );
1174
1175 // Button: Add element from First Select to Second Select.
1176 printf(
1177 '<button id="_src_add_%1$s" class="wpmui-field-input wpmui-tag-button button %2$s" type="button">%3$s</button>',
1178 esc_attr( $id ),
1179 esc_attr( $src_class ),
1180 $button_text
1181 );
1182
1183 $label_tag = $labels;
1184 $label_tag->id = $id;
1185 $label_tag->title = $title_selected;
1186 $label_tag->id = $id;
1187 $label_tag->tooltip = '';
1188 $label_tag->tooltip_code = '';
1189 $label_tag->class .= ' wpmui-tag-label';
1190 $this->element_label( $label_tag );
1191
1192 // Second Select: The actual tag-list
1193 printf(
1194 '<select id="%1$s" class="wpmui-field-input wpmui-field-select wpmui-tag-data %2$s" multiple="multiple" readonly="readonly" %4$s>%5$s</select>',
1195 esc_attr( $id ),
1196 esc_attr( $class ),
1197 esc_attr( $name ),
1198 $ajax_data,
1199 $options_selected
1200 );
1201 }
1202
1203 $this->element_hint( $labels );
1204 $this->wrap_close();
1205 }
1206
1207 /**
1208 * Helper function used by `html_element`
1209 *
1210 * @since 1.1.0
1211 * @internal
1212 */
1213 private function element_wp_pages( $labels, $class, $id, $name, $value, $attr, $field_options, $wrapper_class ) {
1214 $defaults = array(
1215 'hierarchical' => 1,
1216 'sort_column' => 'post_title',
1217 'sort_order' => 'ASC',
1218 'no_item' => '(Select a page)',
1219 );
1220 $args = wp_parse_args( $field_options, $defaults );
1221
1222 $pages = get_pages( $args );
1223 $parent_list = array();
1224 $items = array();
1225
1226 foreach ( $pages as $page ) {
1227 $parent_list[$page->ID] = $page;
1228 }
1229
1230 if ( ! array_key_exists( $value, $parent_list ) ) {
1231 // In case no value is selected set the default to 'no item';
1232 $items[$value] = $args['no_item'];
1233 }
1234
1235 foreach ( $pages as $page_id => $page ) {
1236 $level = 0;
1237 $parent = $page;
1238 while ( $parent->post_parent ) {
1239 $parent = $parent_list[$parent->post_parent];
1240 $level += 1;
1241 }
1242
1243 if ( 0 === strlen( $page->post_title ) ) {
1244 $label = sprintf(
1245 '#%1$s (%2$s)',
1246 $page->ID,
1247 $page->post_name
1248 );
1249 } else {
1250 $label = $page->post_title;
1251 }
1252
1253 $items[$page->ID] = str_repeat( '&nbsp;&mdash;&nbsp;', $level ) . $label;
1254 }
1255
1256 $this->element_select(
1257 $labels,
1258 $class . ' wpmui-wp-pages',
1259 $id,
1260 $name,
1261 $value,
1262 $attr,
1263 $items,
1264 $wrapper_class
1265 );
1266 }
1267
1268 /**
1269 * Helper function used by `html_element`
1270 *
1271 * @since 1.1.0
1272 * @internal
1273 */
1274 private function element_separator( $type = 'horizontal' ) {
1275 if ( 'v' === $type[0] ) {
1276 echo '<div class="wpmui-divider"></div>';
1277 } else {
1278 echo '<div class="wpmui-separator"></div>';
1279 }
1280 }
1281
1282 /**
1283 * Helper function used by `html_element`
1284 *
1285 * @since 1.1.0
1286 * @internal
1287 */
1288 private function element_link( $labels, $class, $id, $label, $url, $attr, $target ) {
1289 $this->element_desc( $labels );
1290
1291 if ( empty( $labels->title ) ) {
1292 $title = $label;
1293 } else {
1294 $title = $labels->title;
1295 }
1296
1297 printf(
1298 '<a id="%1$s" title="%2$s" class="wpmui-link %3$s" href="%4$s" target="%7$s" %6$s>%5$s</a>',
1299 esc_attr( $id ),
1300 esc_attr( strip_tags( $title ) ),
1301 esc_attr( $class ),
1302 esc_url( $url ),
1303 $label,
1304 $attr,
1305 $target
1306 );
1307
1308 $this->element_hint( $labels );
1309 }
1310
1311 /**
1312 * Helper function used by `html_element`
1313 *
1314 * @since 1.1.0
1315 * @internal
1316 */
1317 private function element_wrapper( $labels, $class, $id, $code, $wrap, $wrapper_class ) {
1318 if ( empty( $wrap ) ) { $wrap = 'span'; }
1319
1320 $this->wrap_open( 'html-text', $class, 'span', $wrapper_class );
1321 $this->element_label( $labels );
1322
1323 printf(
1324 '<%1$s class="%2$s">%3$s</%1$s>',
1325 esc_attr( $wrap ),
1326 esc_attr( $class ),
1327 $code
1328 );
1329
1330 $this->element_hint( $labels );
1331 $this->wrap_close();
1332 }
1333
1334 /**
1335 * Helper function used by `html_element`
1336 *
1337 * @since 1.1.0
1338 * @internal
1339 */
1340 private function element_table( $labels, $class, $id, $rows, $args, $wrapper_class ) {
1341 self::$core->array->equip( $args, 'head_row', 'head_col', 'col_class' );
1342
1343 $this->wrap_open( 'table', $class, 'span', $wrapper_class );
1344 $this->element_label( $labels );
1345
1346 $code_body = '';
1347 $code_head = '';
1348
1349 if ( is_array( $rows ) ) {
1350 $args['col_class'] = self::$core->array->get( $args['col_class'] );
1351
1352 foreach ( $rows as $row_num => $row ) {
1353 $code_row = '';
1354 $is_head_row = false;
1355 $row_class = $row_num % 2 === 0 ? '' : 'alternate';
1356
1357 if ( 0 === $row_num && $args['head_row'] ) {
1358 $is_head_row = true;
1359 }
1360
1361 if ( is_array( $row ) ) {
1362 foreach ( $row as $col_num => $col ) {
1363 $is_head = $is_head_row
1364 || ( 0 === $col_num && $args['head_col'] );
1365
1366 $col_class = isset( $args['col_class'][$col_num] )
1367 ? $args['col_class'][$col_num]
1368 : '';
1369
1370 $code_row .= sprintf(
1371 '<%1$s class="%3$s">%2$s</%1$s>',
1372 ($is_head ? 'th' : 'td'),
1373 $col,
1374 $col_class
1375 );
1376 }
1377 } else {
1378 $code_row = $row;
1379 }
1380
1381 $code_row = sprintf(
1382 '<tr class="%2$s">%1$s</tr>',
1383 $code_row,
1384 $row_class
1385 );
1386
1387 if ( $is_head_row ) {
1388 $code_head .= $code_row;
1389 } else {
1390 $code_body .= $code_row;
1391 }
1392 }
1393
1394 printf(
1395 '<table class="wpmui-html-table %1$s">%2$s%3$s</table>',
1396 esc_attr( $class ),
1397 '<thead>' . $code_head . '</thead>',
1398 '<tbody>' . $code_body . '</tbody>'
1399 );
1400 }
1401
1402 $this->element_hint( $labels );
1403 $this->wrap_close();
1404 }
1405
1406 /**
1407 * Returns HTML code containing options used to build a select tag.
1408 *
1409 * @since 1.1.0
1410 * @internal
1411 *
1412 * @param array $list List items as 'key => value' pairs.
1413 * @param array|string $value The selected value.
1414 * @param string $type Either 'default' or 'taglist'.
1415 *
1416 * @return string
1417 */
1418 private function select_options( $list, $value = '', $type = 'default' ) {
1419 $options = '';
1420 $list = self::$core->array->get( $list );
1421
1422 foreach ( $list as $key => $option ) {
1423 if ( is_array( $option ) ) {
1424 if ( empty( $option ) ) { continue; }
1425 $options .= sprintf(
1426 '<optgroup label="%1$s">%2$s</optgroup>',
1427 $key,
1428 $this->select_options( $option, $value, $type )
1429 );
1430 } else {
1431 $attr = '';
1432 if ( is_object( $option ) ) {
1433 if ( isset( $option->attr ) ) { $attr = $option->attr; }
1434 if ( isset( $option->label ) ) { $option = $option->label; }
1435 }
1436 if ( empty( $option ) ) { continue; }
1437
1438 if ( is_array( $value ) ) {
1439 $is_selected = ( in_array( $key, $value ) );
1440 } else {
1441 $is_selected = $key == $value;
1442 }
1443
1444 switch ( $type ) {
1445 case 'default':
1446 $attr .= selected( $is_selected, true, false );
1447 $options .= sprintf(
1448 '<option value="%1$s" %2$s>%3$s</option>',
1449 esc_attr( $key ),
1450 $attr,
1451 $option
1452 );
1453 break;
1454
1455 case 'taglist':
1456 $attr .= ($is_selected ? 'disabled="disabled"' : '');
1457 $options .= sprintf(
1458 '<option value="%1$s" %2$s>%3$s</option>',
1459 esc_attr( $key ),
1460 $attr,
1461 $option
1462 );
1463 break;
1464 }
1465 }
1466 }
1467
1468 return $options;
1469 }
1470
1471 /**
1472 * Output the opening tag of an input wrapper.
1473 *
1474 * @since 2.0.0
1475 * @internal
1476 *
1477 * @param string $type Wrapper type, class is set to 'wpmui-$type-wrapper'.
1478 * @param string $classes String or array containing additional classes.
1479 * All classes are extended with '-wrapper'.
1480 * @param string $tag Optional. The tag name, default 'span'
1481 * @param string $raw_classes String or array containing additional classes.
1482 * These classes are not modified, but output as they appear.
1483 */
1484 private function wrap_open( $type, $classes = '', $tag = 'span', $raw_classes = '' ) {
1485 if ( is_string( $classes ) ) {
1486 $classes = explode( ' ', $classes );
1487 }
1488
1489 if ( count( $classes ) ) {
1490 $classes = array_filter( array_map( 'trim', $classes ) );
1491 $classes = array_map( 'strtolower', $classes );
1492 $extra_classes = implode( '-wrapper ', $classes );
1493 if ( ! empty( $extra_classes ) ) { $extra_classes .= '-wrapper'; }
1494 } else {
1495 $extra_classes = '';
1496 }
1497
1498 if ( ! empty( $raw_classes ) ) {
1499 if ( is_array( $raw_classes ) ) {
1500 $extra_classes .= implode( ' ', $raw_classes );
1501 } else {
1502 $extra_classes .= ' ' . $raw_classes;
1503 }
1504 }
1505 $extra_classes = trim( $extra_classes );
1506
1507 printf(
1508 '<%1$s class="wpmui-wrapper wpmui-%2$s-wrapper %3$s">',
1509 $tag,
1510 $type,
1511 $extra_classes
1512 );
1513 }
1514
1515 /**
1516 * Output the closing tag of an input wrapper.
1517 *
1518 * @since 2.0.0
1519 * @internal
1520 *
1521 * @param string $tag Optional. The tag name, default 'span'
1522 */
1523 private function wrap_close( $tag = 'span' ) {
1524 printf( '</%1$s>', $tag );
1525 }
1526
1527 /**
1528 * Helper function used by `html_element`
1529 *
1530 * @since 1.1.0
1531 * @internal
1532 */
1533 private function element_label( $labels ) {
1534 if ( ! empty( $labels->title ) ) {
1535 printf(
1536 '<%5$s for="%1$s" class="wpmui-field-label %4$s">%2$s %3$s</%5$s>',
1537 esc_attr( $labels->id ),
1538 $labels->title,
1539 $labels->tooltip_code,
1540 esc_attr( ' wpmui-label-' . $labels->id . ' ' . $labels->class ),
1541 esc_attr( $labels->label_type )
1542 );
1543 }
1544
1545 $this->element_desc( $labels );
1546 }
1547
1548 /**
1549 * Helper function used by `html_element`
1550 *
1551 * @since 1.1.0
1552 * @internal
1553 */
1554 private function element_desc( $labels ) {
1555 if ( ! empty( $labels->desc ) ) {
1556 printf(
1557 '<label class="wpmui-field-description %2$s" for="%3$s">%1$s</label >',
1558 $labels->desc,
1559 esc_attr( 'wpmui-description-' . $labels->id . ' ' . $labels->class ),
1560 esc_attr( $labels->id )
1561 );
1562 }
1563
1564 if ( ! empty( $labels->before ) ) {
1565 printf(
1566 '<span class="wpmui-label-before">%s</span>',
1567 $labels->before
1568 );
1569 }
1570 }
1571
1572 /**
1573 * Helper function used by `html_element`
1574 *
1575 * @since 1.1.0
1576 * @internal
1577 */
1578 private function element_hint( $labels ) {
1579 if ( ! empty( $labels->after ) ) {
1580 printf(
1581 '<span class="wpmui-label-after">%s</span>',
1582 $labels->after
1583 );
1584 }
1585
1586 if ( empty( $labels->title ) ) {
1587 echo $labels->tooltip_code;
1588 }
1589 }
1590
1591 /**
1592 * Method for outputting tooltips.
1593 *
1594 * @since 1.1.0
1595 * @api
1596 *
1597 * @param string $tip The tooltip to display.
1598 * @param bool $return Optional. If true then the HTML code is returned as
1599 * function return value. Otherwise echo'ed.
1600 *
1601 * @return string|void Depending on param $return either nothing or HTML code.
1602 */
1603 public function tooltip( $tip = '', $return = false ) {
1604 if ( empty( $tip ) ) { return; }
1605
1606 if ( $return ) { ob_start(); }
1607
1608 $this->wrap_open( 'tooltip', '', 'div' );
1609 ?>
1610 <div class="wpmui-tooltip-wrapper">
1611 <div class="wpmui-tooltip-info"><i class="wpmui-fa wpmui-fa-info-circle"></i></div>
1612 <div class="wpmui-tooltip">
1613 <div class="wpmui-tooltip-button">&times;</div>
1614 <div class="wpmui-tooltip-content">
1615 <?php echo $tip; ?>
1616 </div>
1617 </div>
1618 <?php
1619 $this->wrap_close( 'div' );
1620
1621 if ( $return ) { return ob_get_clean(); }
1622 }
1623
1624 }