PluginProbe
WPB Addons for Elementor – News Ticker, Timeline, Team & More Widgets / 1.2
WPB Addons for Elementor – News Ticker, Timeline, Team & More Widgets v1.2
trunk 1.0.8.7 1.0.8.8 1.0.8.9 1.0.9 1.2 1.3 1.4 1.5 1.6 1.7
wpb-elementor-addons / admin / class.settings-api.php

class.settings-api.php in WPB Addons for Elementor – News Ticker, Timeline, Team & More Widgets 1.2, at admin/class.settings-api.php

889 lines 27.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The weDevs Settings API wrapper class modified for WPB Elementor addons.
4 *
5 * @package WPB Elementor Addons
6 */
7
8 if ( ! class_exists( 'WPB_EA_WeDevs_Settings_API' ) ) :
9 /**
10 * The Settings API Class.
11 */
12 class WPB_EA_WeDevs_Settings_API {
13
14 /**
15 * Settings sections array.
16 *
17 * @var array
18 */
19 protected $settings_sections = array();
20
21 /**
22 * Settings fields array.
23 *
24 * @var array
25 */
26 protected $settings_fields = array();
27
28 /**
29 * Class Constructor.
30 */
31 public function __construct() {
32 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
33 }
34
35 /**
36 * Enqueue scripts and styles.
37 */
38 public function admin_enqueue_scripts() {
39 wp_enqueue_style( 'wp-color-picker' );
40 wp_enqueue_media();
41 wp_enqueue_script( 'wp-color-picker' );
42 wp_enqueue_script( 'jquery' );
43 }
44
45 /**
46 * Set settings sections
47 *
48 * @param array $sections setting sections array.
49 */
50 public function set_sections( $sections ) {
51 $this->settings_sections = $sections;
52
53 return $this;
54 }
55
56 /**
57 * Add a single section
58 *
59 * @param array $section The settings section.
60 */
61 public function add_section( $section ) {
62 $this->settings_sections[] = $section;
63
64 return $this;
65 }
66
67 /**
68 * Set settings fields.
69 *
70 * @param array $fields settings fields array.
71 */
72 public function set_fields( $fields ) {
73 $this->settings_fields = $fields;
74
75 return $this;
76 }
77
78 /**
79 * Add settings field.
80 *
81 * @param [type] $section The settings section.
82 * @param [type] $field The settings field.
83 * @return array
84 */
85 public function add_field( $section, $field ) {
86 $defaults = array(
87 'name' => '',
88 'label' => '',
89 'desc' => '',
90 'type' => 'text',
91 );
92
93 $arg = wp_parse_args( $field, $defaults );
94 $this->settings_fields[ $section ][] = $arg;
95
96 return $this;
97 }
98
99 /**
100 * Initialize and registers the settings sections and fileds to WordPress
101 *
102 * Usually this should be called at `admin_init` hook.
103 *
104 * This function gets the initiated settings sections and fields. Then
105 * registers them to WordPress and ready for use.
106 */
107 public function admin_init() {
108 // register settings sections.
109 foreach ( $this->settings_sections as $section ) {
110 if ( false === get_option( $section['id'] ) ) {
111 add_option( $section['id'] );
112 }
113
114 if ( isset( $section['desc'] ) && ! empty( $section['desc'] ) ) {
115 $section['desc'] = '<div class="inside">' . $section['desc'] . '</div>';
116 $callback = function () use ( $section ) {
117 echo wp_kses_post( str_replace( '"', '\"', $section['desc'] ) );
118 };
119 } elseif ( isset( $section['callback'] ) ) {
120 $callback = $section['callback'];
121 } else {
122 $callback = null;
123 }
124
125 add_settings_section( $section['id'], $section['title'], $callback, $section['id'] );
126 }
127
128 // register settings fields.
129 foreach ( $this->settings_fields as $section => $field ) {
130 foreach ( $field as $option ) {
131
132 $name = $option['name'];
133 $type = isset( $option['type'] ) ? $option['type'] : 'text';
134 $label = isset( $option['label'] ) ? $option['label'] : '';
135 $callback = isset( $option['callback'] ) ? $option['callback'] : array( $this, 'callback_' . $type );
136
137 $args = array(
138 'id' => $name,
139 'class' => isset( $option['class'] ) ? $option['class'] : $name,
140 'label_for' => "{$section}[{$name}]",
141 'desc' => isset( $option['desc'] ) ? $option['desc'] : '',
142 'name' => $label,
143 'section' => $section,
144 'size' => isset( $option['size'] ) ? $option['size'] : null,
145 'options' => isset( $option['options'] ) ? $option['options'] : '',
146 'std' => isset( $option['default'] ) ? $option['default'] : '',
147 'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
148 'type' => $type,
149 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : '',
150 'min' => isset( $option['min'] ) ? $option['min'] : '',
151 'max' => isset( $option['max'] ) ? $option['max'] : '',
152 'step' => isset( $option['step'] ) ? $option['step'] : '',
153 'icon' => isset( $option['icon'] ) ? $option['icon'] : '',
154 );
155
156 add_settings_field( "{$section}[{$name}]", $label, $callback, $section, $section, $args );
157 }
158 }
159
160 // creates our settings in the options table.
161 foreach ( $this->settings_sections as $section ) {
162 register_setting( $section['id'], $section['id'], array( $this, 'sanitize_options' ) );
163 }
164 }
165
166 /**
167 * Get field description for display
168 *
169 * @param array $args settings field args.
170 */
171 public function get_field_description( $args ) {
172 if ( ! empty( $args['desc'] ) ) {
173 $desc = sprintf( '<p class="description">%s</p>', $args['desc'] );
174 } else {
175 $desc = '';
176 }
177
178 return $desc;
179 }
180
181 /**
182 * Displays a text field for a settings field
183 *
184 * @param array $args settings field args.
185 */
186 public function callback_text( $args ) {
187
188 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
189 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
190 $type = isset( $args['type'] ) ? $args['type'] : 'text';
191 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
192
193 $html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );
194 $html .= $this->get_field_description( $args );
195
196 echo $html;
197 }
198
199 /**
200 * Displays a url field for a settings field
201 *
202 * @param array $args settings field args.
203 */
204 public function callback_url( $args ) {
205 $this->callback_text( $args );
206 }
207
208 /**
209 * Displays a number field for a settings field
210 *
211 * @param array $args settings field args.
212 */
213 public function callback_number( $args ) {
214 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
215 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
216 $type = isset( $args['type'] ) ? $args['type'] : 'number';
217 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
218 $min = ( '' === $args['min'] ) ? '' : ' min="' . $args['min'] . '"';
219 $max = ( '' === $args['max'] ) ? '' : ' max="' . $args['max'] . '"';
220 $step = ( '' === $args['step'] ) ? '' : ' step="' . $args['step'] . '"';
221
222 $html = sprintf( '<input type="%1$s" class="%2$s-number" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );
223 $html .= $this->get_field_description( $args );
224
225 echo $html;
226 }
227
228 /**
229 * Displays a checkbox for a settings field
230 *
231 * @param array $args settings field args.
232 */
233 public function callback_checkbox( $args ) {
234
235 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
236
237 $html = '<fieldset>';
238 $html .= sprintf( '<label for="wpuf-%1$s[%2$s]">', $args['section'], $args['id'] );
239 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id'] );
240 $html .= sprintf( '<input type="checkbox" class="checkbox" id="wpuf-%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked( $value, 'on', false ) );
241 $html .= sprintf( '%1$s</label>', $args['desc'] );
242 $html .= '</fieldset>';
243
244 echo $html;
245 }
246
247 /**
248 * Displays a toggle for a settings field
249 *
250 * @param array $args settings field args.
251 */
252 public function callback_toggle( $args ) {
253
254 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
255
256 $html = '<fieldset>';
257 $html .= sprintf( '<label class="toggle-btn' . esc_attr( 'on' === $value ? ' active' : '' ) . '" for="wpuf-%1$s[%2$s]">', $args['section'], $args['id'] );
258 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id'] );
259 $html .= sprintf( '<input type="checkbox" class="checkbox cb-value" id="wpuf-%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked( $value, 'on', false ) );
260 $html .= '<span class="round-btn"></span>';
261 $html .= '</label>';
262 $html .= '</fieldset>';
263
264 echo $html;
265 }
266
267 /**
268 * Displays a toggle for a settings field
269 *
270 * @param array $args settings field args.
271 */
272 public function callback_premium( $args ) {
273
274 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
275
276 $html = '<fieldset>';
277 $html .= sprintf( '<label class="toggle-btn' . esc_attr( $value === 'on' ? ' active' : '' ) . '" for="wpuf-%1$s[%2$s]">', $args['section'], $args['id'] );
278 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id'] );
279 $html .= sprintf( '<input type="checkbox" class="checkbox cb-value" id="wpuf-%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked( $value, 'on', false ) );
280 $html .= '<span class="round-btn"></span>';
281 $html .= '</label>';
282 $html .= '</fieldset>';
283
284 echo $html;
285 }
286
287 /**
288 * Displays a toggle for a settings field
289 *
290 * @param array $args settings field args.
291 */
292 public function callback_section_title( $args ) {
293
294 $html = '<fieldset class="wpb-ea-section-title-area">';
295 $html .= '<h2 class="wpb-ea-section-title">';
296 $html .= esc_html( $args['name'] );
297 $html .= '</h2>';
298
299 if ( array_key_exists( 'desc', $args ) ) {
300 if ( $args['desc'] ) {
301 $html .= sprintf( '<p class="about-text">%1$s</p>', $args['desc'] );
302 }
303 }
304
305 $html .= '</fieldset>';
306
307 echo $html;
308 }
309
310 /**
311 * Displays a multicheckbox for a settings field
312 *
313 * @param array $args settings field args.
314 */
315 public function callback_multicheck( $args ) {
316
317 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
318 $html = '<fieldset>';
319 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="" />', $args['section'], $args['id'] );
320 foreach ( $args['options'] as $key => $label ) {
321 $checked = isset( $value[ $key ] ) ? $value[ $key ] : '0';
322 $html .= sprintf( '<label for="wpuf-%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
323 $html .= sprintf( '<input type="checkbox" class="checkbox" id="wpuf-%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $checked, $key, false ) );
324 $html .= sprintf( '%1$s</label><br>', $label );
325 }
326
327 $html .= $this->get_field_description( $args );
328 $html .= '</fieldset>';
329
330 echo $html;
331 }
332
333 /**
334 * Displays a radio button for a settings field
335 *
336 * @param array $args settings field args.
337 */
338 public function callback_radio( $args ) {
339
340 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
341 $html = '<fieldset>';
342
343 foreach ( $args['options'] as $key => $label ) {
344 $html .= sprintf( '<label for="wpuf-%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
345 $html .= sprintf( '<input type="radio" class="radio" id="wpuf-%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $value, $key, false ) );
346 $html .= sprintf( '%1$s</label><br>', $label );
347 }
348
349 $html .= $this->get_field_description( $args );
350 $html .= '</fieldset>';
351
352 echo $html;
353 }
354
355 /**
356 * Displays a selectbox for a settings field
357 *
358 * @param array $args settings field args.
359 */
360 public function callback_select( $args ) {
361
362 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
363 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
364 $html = sprintf( '<select class="%1$s" name="%2$s[%3$s]" id="%2$s[%3$s]">', $size, $args['section'], $args['id'] );
365
366 foreach ( $args['options'] as $key => $label ) {
367 $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $value, $key, false ), $label );
368 }
369
370 $html .= sprintf( '</select>' );
371 $html .= $this->get_field_description( $args );
372
373 echo $html;
374 }
375
376 /**
377 * Displays a textarea for a settings field
378 *
379 * @param array $args settings field args.
380 */
381 public function callback_textarea( $args ) {
382
383 $value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
384 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
385 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
386
387 $html = sprintf( '<textarea rows="5" cols="55" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );
388 $html .= $this->get_field_description( $args );
389
390 echo $html;
391 }
392
393 /**
394 * Displays the html for a settings field.
395 *
396 * @param [type] $args Settings field args.
397 * @return void
398 */
399 public function callback_html( $args ) {
400 echo wp_kses_post( $this->get_field_description( $args ) );
401 }
402
403 /**
404 * Displays a rich text textarea for a settings field
405 *
406 * @param array $args settings field args.
407 */
408 public function callback_wysiwyg( $args ) {
409
410 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
411 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : '500px';
412
413 echo '<div style="max-width: ' . esc_html( $size ) . ';">';
414
415 $editor_settings = array(
416 'teeny' => true,
417 'textarea_name' => $args['section'] . '[' . $args['id'] . ']',
418 'textarea_rows' => 10,
419 );
420
421 if ( isset( $args['options'] ) && is_array( $args['options'] ) ) {
422 $editor_settings = array_merge( $editor_settings, $args['options'] );
423 }
424
425 wp_editor( $value, $args['section'] . '-' . $args['id'], $editor_settings );
426
427 echo '</div>';
428
429 echo esc_html( $this->get_field_description( $args ) );
430 }
431
432 /**
433 * Displays a file upload field for a settings field
434 *
435 * @param array $args settings field args.
436 */
437 public function callback_file( $args ) {
438
439 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
440 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
441 $id = $args['section'] . '[' . $args['id'] . ']';
442 $label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : esc_html__( 'Choose File', 'wpb-elementor-addons' );
443
444 $html = sprintf( '<input type="text" class="%1$s-text wpsa-url" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
445 $html .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
446 $html .= $this->get_field_description( $args );
447
448 echo $html;
449 }
450
451 /**
452 * Displays a password field for a settings field
453 *
454 * @param array $args settings field args.
455 */
456 public function callback_password( $args ) {
457
458 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
459 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
460
461 $html = sprintf( '<input type="password" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
462 $html .= $this->get_field_description( $args );
463
464 echo $html;
465 }
466
467 /**
468 * Displays a color picker field for a settings field
469 *
470 * @param array $args settings field args.
471 */
472 public function callback_color( $args ) {
473
474 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
475 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
476
477 $html = sprintf( '<input type="text" class="%1$s-text wp-color-picker-field" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s" data-default-color="%5$s" />', $size, $args['section'], $args['id'], $value, $args['std'] );
478 $html .= $this->get_field_description( $args );
479
480 echo $html;
481 }
482
483 /**
484 * Displays a select box for creating the pages select box.
485 *
486 * @param array $args Settings field args.
487 */
488 public function callback_pages( $args ) {
489
490 $dropdown_args = array(
491 'selected' => esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) ),
492 'name' => $args['section'] . '[' . $args['id'] . ']',
493 'id' => $args['section'] . '[' . $args['id'] . ']',
494 'echo' => 0,
495 );
496 $html = wp_dropdown_pages( $dropdown_args );
497 echo $html;
498 }
499
500 /**
501 * Sanitize callback for Settings API.
502 *
503 * @param [type] $options The settings options.
504 * @return array
505 */
506 public function sanitize_options( $options ) {
507
508 if ( ! $options ) {
509 return $options;
510 }
511
512 foreach ( $options as $option_slug => $option_value ) {
513 $sanitize_callback = $this->get_sanitize_callback( $option_slug );
514
515 // If callback is set, call it.
516 if ( $sanitize_callback ) {
517 $options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
518 continue;
519 }
520 }
521
522 return $options;
523 }
524
525 /**
526 * Get sanitization callback for given option slug.
527 *
528 * @param string $slug Option slug.
529 *
530 * @return mixed String or bool false.
531 */
532 public function get_sanitize_callback( $slug = '' ) {
533 if ( empty( $slug ) ) {
534 return false;
535 }
536
537 // Iterate over registered fields and see if we can find proper callback.
538 foreach ( $this->settings_fields as $section => $options ) {
539 foreach ( $options as $option ) {
540 if ( $option['name'] !== $slug ) {
541 continue;
542 }
543
544 // Return the callback name.
545 return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
546 }
547 }
548
549 return false;
550 }
551
552 /**
553 * Get the value of a settings field.
554 *
555 * @param string $option Settings field name.
556 * @param string $section The section name this field belongs to.
557 * @param string $default_value Default text if it's not found.
558 * @return string
559 */
560 public function get_option( $option, $section, $default_value = '' ) {
561
562 $options = get_option( $section );
563
564 if ( isset( $options[ $option ] ) ) {
565 return $options[ $option ];
566 }
567
568 return $default_value;
569 }
570
571 /**
572 * Show navigations as tab
573 *
574 * Shows all the settings section labels as tab
575 */
576 public function show_navigation() {
577 $html = '<div class="nav-tab-wrapper">';
578
579 $count = count( $this->settings_sections );
580
581 // don't show the navigation if only one section exists.
582 if ( 1 === $count ) {
583 return;
584 }
585
586 foreach ( $this->settings_sections as $tab ) {
587
588 if ( array_key_exists( 'icon', $tab ) ) {
589 $html .= sprintf( '<a href="#%1$s" class="nav-tab" id="%1$s-tab"><i class="%3$s"></i>%2$s</a>', $tab['id'], $tab['title'], $tab['icon'] );
590 } else {
591 $html .= sprintf( '<a href="#%1$s" class="nav-tab" id="%1$s-tab">%2$s</a>', $tab['id'], $tab['title'] );
592 }
593 }
594
595 $html .= '</div>';
596
597 echo wp_kses_post( $html );
598 }
599
600 /**
601 * Prints out all settings sections added to a particular settings page.
602 *
603 * @param [type] $page The settings page.
604 * @return void
605 */
606 public function do_settings_sections( $page ) {
607 global $wp_settings_sections, $wp_settings_fields;
608
609 if ( ! isset( $wp_settings_sections[ $page ] ) ) {
610 return;
611 }
612
613 foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
614
615 if ( $section['title'] ) {
616 echo '<h2>' . esc_html( $section['title'] ) . '</h2>';
617 }
618
619 if ( $section['callback'] ) {
620 call_user_func( $section['callback'], $section );
621 }
622
623 if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
624 continue;
625 }
626 echo '<div class="form-addons-container">';
627 $this->do_settings_fields( $page, $section['id'] );
628 echo '</div>';
629 }
630 }
631
632 /**
633 * Print out the settings fields for a particular settings section.
634 *
635 * Part of the Settings API. Use this in a settings page to output
636 * a specific section. Should normally be called by do_settings_sections()
637 * rather than directly.
638 *
639 * @global $wp_settings_fields Storage array of settings fields and their pages/sections.
640 *
641 * @since 2.7.0
642 *
643 * @param string $page Slug title of the admin page whose settings fields you want to show.
644 * @param string $section Slug title of the settings section whose fields you want to show.
645 */
646 public function do_settings_fields( $page, $section ) {
647 global $wp_settings_fields;
648
649 if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
650 return;
651 }
652
653 foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) {
654
655 $class = '';
656
657 if ( 'section_title' === $field['args']['type'] ) {
658 $class = 'form-addon form-addons-section-title';
659 } elseif ( ! empty( $field['args']['class'] ) ) {
660 $class = 'form-addon ' . esc_attr( $field['args']['class'] );
661 }
662
663 if ( 'premium' === $field['args']['type'] ) {
664
665 echo '<div class="' . esc_attr( $class ) . '">';
666 echo '<div class="form-addon-inner">';
667 echo '<a class="addon-pro-link" target="_blank" href="' . esc_url( $field['args']['options'] ) . '"></a>';
668 echo '<div class="addon-name">';
669 if ( array_key_exists( 'icon', $field['args'] ) ) {
670 if ( $field['args']['icon'] ) {
671 echo '<i class="' . esc_attr( $field['args']['icon'] ) . '"></i>';
672 }
673 }
674 echo '<h3 class="addon-title">' . esc_html( $field['title'] ) . '</h3>';
675 if ( $field['args']['desc'] ) {
676 echo '<span class="addon-desc">' . esc_html( $field['args']['desc'] ) . '</span>';
677 }
678
679 echo '</div>';
680
681 echo '<div class="addon-switch addon-pro-label">';
682 echo esc_html__( 'Pro', 'wpb-elementor-addons' );
683 echo '</div>';
684 echo '</div>';
685 echo '</div>';
686 } else {
687
688 echo '<div class="' . esc_attr( $class ) . '">';
689 echo '<div class="form-addon-inner">';
690 echo '<div class="addon-name">';
691 if ( array_key_exists( 'icon', $field['args'] ) ) {
692 if ( $field['args']['icon'] ) {
693 echo '<i class="' . esc_attr( $field['args']['icon'] ) . '"></i>';
694 }
695 }
696 echo '<h3 class="addon-title">' . esc_html( $field['title'] ) . '</h3>';
697 if ( $field['args']['desc'] ) {
698 echo '<span class="addon-desc">' . esc_html( $field['args']['desc'] ) . '</span>';
699 }
700
701 echo '</div>';
702
703 echo '<div class="addon-switch">';
704 call_user_func( $field['callback'], $field['args'] );
705 echo '</div>';
706 echo '</div>';
707 echo '</div>';
708 }
709 }
710 }
711
712 /**
713 * Show the section settings forms
714 *
715 * This function displays every sections in a different form
716 */
717 public function show_forms() {
718 ?>
719 <div class="metabox-holder">
720 <?php foreach ( $this->settings_sections as $form ) { ?>
721 <div id="<?php echo esc_attr( $form['id'] ); ?>" class="group" style="display: none;">
722 <form method="post" action="options.php">
723 <div class="wpb-ea-settings-submit wpb-ea-settings-submit-top">
724 <div class="wpb-ea-settings-submit-top-inner">
725 <div class="wpb-ea-settings-title">
726 <h3>WPB Elementor Addons Settings</h3>
727 <p>Use this code for 10% off for the <a href="https://wpbean.com/elementor-addons/" target="_blank">premium addons</a> - 10PERCENTOFF</p>
728 </div>
729 <?php submit_button(); ?>
730 </div>
731 </div>
732 <?php
733 do_action( 'wsa_form_top_' . $form['id'], $form );
734 settings_fields( $form['id'] );
735
736 if ( array_key_exists( 'addons', $form ) ) {
737 $this->do_settings_sections( $form['id'] );
738 } else {
739 do_settings_sections( $form['id'] );
740 }
741
742 do_action( 'wsa_form_bottom_' . $form['id'], $form );
743 if ( isset( $this->settings_fields[ $form['id'] ] ) ) :
744 ?>
745 <div class="wpb-ea-settings-submit">
746 <?php submit_button(); ?>
747 </div>
748 <?php endif; ?>
749 </form>
750 </div>
751 <?php } ?>
752 </div>
753 <?php
754 $this->script();
755 }
756
757 /**
758 * Tabbable JavaScript codes & Initiate Color Picker
759 *
760 * This code uses localstorage for displaying active tabs
761 */
762 public function script() {
763 ?>
764 <script>
765 jQuery(document).ready(function($) {
766 // toggle
767 $('.cb-value').click(function() {
768 var mainParent = $(this).parent('.toggle-btn');
769 if($(mainParent).find('input.cb-value').is(':checked')) {
770 $(mainParent).addClass('active');
771 } else {
772 $(mainParent).removeClass('active');
773 }
774 });
775
776 // Settings sticky top
777 $(document).ready(function() {
778 var stickyTop = $('.wpb-ea-settings-submit-top').offset().top;
779
780 $(window).scroll(function() {
781 var windowTop = $(window).scrollTop();
782 if (stickyTop < windowTop && $(".wpb-ea-settings-wrap").height() + $(".wpb-ea-settings-wrap").offset().top - $(".wpb-ea-settings-submit-top").height() > windowTop) {
783 $('.wpb-ea-settings-submit-top').addClass('wpb-ea-settings-submit-top-fixed');
784 } else {
785 $('.wpb-ea-settings-submit-top').removeClass('wpb-ea-settings-submit-top-fixed');
786 }
787 });
788 });
789
790 //Initiate Color Picker
791 $('.wp-color-picker-field').wpColorPicker();
792
793 // Switches option sections
794 $('.group').hide();
795 var activetab = '';
796 if (typeof(localStorage) != 'undefined' ) {
797 activetab = localStorage.getItem("activetab");
798 }
799
800 //if url has section id as hash then set it as active or override the current local storage value
801 if(window.location.hash){
802 activetab = window.location.hash;
803 if (typeof(localStorage) != 'undefined' ) {
804 localStorage.setItem("activetab", activetab);
805 }
806 }
807
808 if (activetab != '' && $(activetab).length ) {
809 $(activetab).fadeIn();
810 } else {
811 $('.group:first').fadeIn();
812 }
813 $('.group .collapsed').each(function(){
814 $(this).find('input:checked').parent().parent().parent().nextAll().each(
815 function(){
816 if ($(this).hasClass('last')) {
817 $(this).removeClass('hidden');
818 return false;
819 }
820 $(this).filter('.hidden').removeClass('hidden');
821 });
822 });
823
824 if (activetab != '' && $(activetab + '-tab').length ) {
825 $(activetab + '-tab').addClass('nav-tab-active');
826 }
827 else {
828 $('.nav-tab-wrapper a:first').addClass('nav-tab-active');
829 }
830 $('.nav-tab-wrapper a').click(function(evt) {
831 $('.nav-tab-wrapper a').removeClass('nav-tab-active');
832 $(this).addClass('nav-tab-active').blur();
833 var clicked_group = $(this).attr('href');
834 if (typeof(localStorage) != 'undefined' ) {
835 localStorage.setItem("activetab", $(this).attr('href'));
836 }
837 $('.group').hide();
838 $(clicked_group).fadeIn();
839 evt.preventDefault();
840 });
841
842 $('.wpsa-browse').on('click', function (event) {
843 event.preventDefault();
844
845 var self = $(this);
846
847 // Create the media frame.
848 var file_frame = wp.media.frames.file_frame = wp.media({
849 title: self.data('uploader_title'),
850 button: {
851 text: self.data('uploader_button_text'),
852 },
853 multiple: false
854 });
855
856 file_frame.on('select', function () {
857 attachment = file_frame.state().get('selection').first().toJSON();
858 self.prev('.wpsa-url').val(attachment.url).change();
859 });
860
861 // Finally, open the modal
862 file_frame.open();
863 });
864 });
865 </script>
866 <?php
867 $this->add_style();
868 }
869
870 /**
871 * Add Style.
872 *
873 * @return void
874 */
875 public function add_style() {
876 global $wp_version;
877 if ( version_compare( $wp_version, '3.8', '<=' ) ) :
878 ?>
879 <style type="text/css">
880 /** WordPress 3.8 Fix **/
881 .form-table th { padding: 20px 10px; }
882 #wpbody-content .metabox-holder { padding-top: 5px; }
883 </style>
884 <?php
885 endif;
886 }
887 }
888
889 endif;