PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 1.5.0
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v1.5.0
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
ultimate-store-kit / admin / class-settings-api.php

class-settings-api.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 1.5.0, at admin/class-settings-api.php

970 lines 43.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!class_exists('UltimateStoreKit_Settings_API')) :
4
5 class UltimateStoreKit_Settings_API {
6
7 /**
8 * settings sections array
9 *
10 * @var array
11 */
12 protected $settings_sections = array();
13
14 /**
15 * Settings fields array
16 *
17 * @var array
18 */
19 protected $settings_fields = array();
20
21 public function __construct() {
22 add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
23
24 add_action('wp_ajax_ultimate_store_kit_settings_save', [$this, "ultimate_store_kit_settings_save"]);
25 }
26
27 /**
28 * Enqueue scripts and styles
29 */
30 function admin_enqueue_scripts() {
31 wp_enqueue_script('jquery');
32 }
33
34 /**
35 * Set settings sections
36 *
37 * @param array $sections setting sections array
38 */
39 function set_sections($sections) {
40 $this->settings_sections = $sections;
41
42 return $this;
43 }
44
45 /**
46 * Add a single section
47 *
48 * @param array $section
49 */
50 function add_section($section) {
51 $this->settings_sections[] = $section;
52
53 return $this;
54 }
55
56 /**
57 * Set settings fields
58 *
59 * @param array $fields settings fields array
60 */
61 function set_fields($fields) {
62 $this->settings_fields = $fields;
63
64 return $this;
65 }
66
67 function add_field($section, $field) {
68 $defaults = array(
69 'name' => '',
70 'label' => '',
71 'desc' => '',
72 'type' => 'text'
73 );
74
75 $arg = wp_parse_args($field, $defaults);
76 $this->settings_fields[$section][] = $arg;
77
78 return $this;
79 }
80
81 function do_settings_sections($page) {
82 global $wp_settings_sections, $wp_settings_fields;
83
84 if (!isset($wp_settings_sections[$page])) {
85 return;
86 }
87
88 foreach ((array) $wp_settings_sections[$page] as $section) {
89 if ($section['id'] == 'ultimate_store_kit_api_settings') {
90 $section_class = ' bdt-child-width-1-3@xl';
91 } else {
92 $section_class = ' bdt-grid-small bdt-child-width-1-4@xl';
93 }
94
95 if ($section['callback']) {
96 call_user_func($section['callback'], $section);
97 }
98
99 if (!isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']])) {
100 continue;
101 }
102 echo '<div class="bdt-options bdt-grid bdt-child-width-1-1 bdt-child-width-1-2@m bdt-child-width-1-3@l' . esc_attr($section_class) . '" role="presentation" bdt-grid="masonry: true">';
103 $this->do_settings_fields($page, $section['id']);
104 echo '</div>';
105 }
106 }
107
108
109 function do_settings_fields($page, $section) {
110 global $wp_settings_fields;
111
112 if (!isset($wp_settings_fields[$page][$section])) {
113 return;
114 }
115
116 foreach ((array) $wp_settings_fields[$page][$section] as $field) {
117 $class = '';
118
119 if (!empty($field['args']['class'])) {
120 $class .= ' ' . esc_attr($field['args']['class']);
121 }
122
123 if (!empty($field['args']['widget_type'])) {
124 $class .= ' usk-widget-' . esc_attr($field['args']['widget_type']);
125 }
126
127 if (!empty($field['args']['widget_type']) && 'pro' == $field['args']['widget_type'] && true !== _is_usk_pro_activated()) {
128 $class .= ' usk-pro-inactive';
129 }
130
131 $used_widgets = self::get_used_widgets_obj();
132 $widget_name = 'usk-' . str_replace(' ', '-', strtolower($field['args']['id']));
133 $used_widgets_count = 0;
134
135 if (isset($used_widgets)) {
136 $used_widgets_count = (in_array($widget_name, array_keys($used_widgets)) ? $used_widgets[$widget_name] : 0);
137 if ($used_widgets_count === 0) {
138 $widget_name = str_replace('_', '-', $widget_name);
139 $used_widgets_count = (in_array($widget_name, array_keys($used_widgets)) ? $used_widgets[$widget_name] : 0);
140 }
141 }
142
143 $widget_used_status = ' usk-used'; // default used class
144 if ($used_widgets_count === 0) {
145 $widget_used_status = ' usk-unused'; // replace by unused class
146 }
147
148 $data_type = ' data-widget-type="' . esc_attr($field['args']['widget_type']) . '" data-content-type="' . esc_attr($field['args']['content_type']) . esc_attr($widget_used_status) . '" data-widget-name="' . strtolower($field['args']['name']) . '"';
149
150
151 if (!empty($field['args']['widget_type']) && 'pro' == $field['args']['widget_type'] && true !== _is_usk_pro_activated()) {
152 $data_type .= ' bdt-tooltip="Pro widget only works with Pro version."';
153 }
154
155 echo "<div class='usk-option-item {$class} {$widget_used_status}' {$data_type}>";
156
157 // printf('<div class="bdt-option-item %1$s" data-widget-type="%2$s" data-content-type="%3$s" data-widget-name="%4$s">', esc_attr($class), esc_attr($field['args']['widget_type']), esc_attr($field['args']['content_type']), esc_attr(strtolower($field['args']['name'])));
158
159 call_user_func($field['callback'], $field['args']);
160
161 echo '</div>';
162 }
163 }
164
165 /**
166 * Initialize and registers the settings sections and fileds to WordPress
167 *
168 * Usually this should be called at `admin_init` hook.
169 *
170 * This function gets the initiated settings sections and fields. Then
171 * registers them to WordPress and ready for use.
172 */
173 function admin_init() {
174 //register settings sections
175 foreach ($this->settings_sections as $section) {
176 if (false == get_option($section['id'])) {
177 add_option($section['id']);
178 }
179
180 if (isset($section['desc']) && !empty($section['desc'])) {
181 $section['desc'] = '<div class="inside">' . esc_html($section['desc']) . '</div>';
182 $callback = function () use ($section) {
183 echo str_replace('"', '\"', esc_html($section['desc']));
184 };
185 } elseif (isset($section['callback'])) {
186 $callback = $section['callback'];
187 } else {
188 $callback = null;
189 }
190
191 add_settings_section($section['id'], $section['title'], $callback, $section['id']);
192 }
193
194 //register settings fields
195 foreach ($this->settings_fields as $section => $field) {
196 foreach ($field as $option) {
197 $name = $option['name'];
198 $type = isset($option['type']) ? $option['type'] : 'text';
199 $label = isset($option['label']) ? $option['label'] : '';
200 $callback = isset($option['callback']) ? $option['callback'] : array($this, 'callback_' . $type);
201
202 $args = array(
203 'id' => $name,
204 'class' => isset($option['class']) ? 'bdt-' . $name . ' ' . $option['class'] : 'bdt-' . $name,
205 'label_for' => "bdt-{$section}[{$name}]",
206 'desc' => isset($option['desc']) ? $option['desc'] : '',
207 'name' => $label,
208 'section' => $section,
209 'size' => isset($option['size']) ? $option['size'] : null,
210 'options' => isset($option['options']) ? $option['options'] : '',
211 'std' => isset($option['default']) ? $option['default'] : '',
212 'sanitize_callback' => isset($option['sanitize_callback']) ? $option['sanitize_callback'] : '',
213 'type' => $type,
214 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : '',
215 'min' => isset($option['min']) ? $option['min'] : '',
216 'max' => isset($option['max']) ? $option['max'] : '',
217 'step' => isset($option['step']) ? $option['step'] : '',
218 'plugin_name' => !empty($option['plugin_name']) ? $option['plugin_name'] : null,
219 'plugin_path' => !empty($option['plugin_path']) ? $option['plugin_path'] : null,
220 'paid' => !empty($option['paid']) ? $option['paid'] : null,
221 'widget_type' => !empty($option['widget_type']) ? $option['widget_type'] : null,
222 'content_type' => !empty($option['content_type']) ? $option['content_type'] : null,
223 'demo_url' => !empty($option['demo_url']) ? $option['demo_url'] : null,
224 'video_url' => !empty($option['video_url']) ? $option['video_url'] : null,
225 );
226
227 add_settings_field("{$section}[{$name}]", $label, $callback, $section, $section, $args);
228 }
229 }
230
231 // creates our settings in the options table
232 foreach ($this->settings_sections as $section) {
233 register_setting($section['id'], $section['id'], array($this, 'sanitize_options'));
234 }
235 }
236
237 /**
238 * Get field description for display
239 *
240 * @param array $args settings field args
241 */
242 public function get_field_description($args) {
243 if (!empty($args['desc'])) {
244 $desc = sprintf('<p class="description">%s</p>', esc_html($args['desc']));
245 } else {
246 $desc = '';
247 }
248
249 return $desc;
250 }
251 public function get_control_output($output) {
252
253
254 $tags = [
255 'div' => ['class' => [], 'bdt-grid' => []],
256 'a' => ['href' => [], 'id' => [], 'target' => [], 'class' => [], 'data-bdt-tooltip' => [], 'data-tab-index' => []],
257 'label' => ['for' => []],
258 'span' => ['scope' => [], 'class' => []],
259 'input' => ['type' => [], 'class' => [], 'id' => [], 'name' => [], 'value' => [], 'placeholder' => [], 'checked' => []],
260 'i' => ['class' => [], 'aria-hidden' => []],
261 'fieldset' => [],
262 'br' => [],
263 'select' => [
264 'class' => [],
265 'name' => [],
266 'id' => [],
267 ],
268 'option' => [
269 'value' => [],
270 'selected' => []
271 ],
272 'h3' => [
273 'class' => []
274 ],
275 'hr' => [
276 'class' => []
277 ],
278 'ul' => [
279 'class' => [],
280 'bdt-tab' => [],
281 ],
282 'li' => [],
283 ];
284
285 if (isset($output)) {
286 echo wp_kses($output, $tags);
287 }
288 }
289
290 /**
291 * Displays a text field for a settings field
292 *
293 * @param array $args settings field args
294 */
295 function callback_text($args) {
296
297 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
298 $class = 'bdt-input';
299 $type = isset($args['type']) ? $args['type'] : 'text';
300 $placeholder = empty($args['placeholder']) ? '' : ' placeholder="' . $args['placeholder'] . '"';
301 $html = '';
302
303
304 $html .= '<div class="bdt-option-item-inner">';
305 if ($args['video_url']) {
306 $html .= '<a href="' . $args['video_url'] . '" target="_blank" class="bdt-option-video" bdt-tooltip="View ' . $args['name'] . ' Video Tutorial"><i class="usk-icon-tutorial" aria-hidden="true"></i></a>';
307 }
308 $html .= sprintf('<label for="bdt_%1$s[%2$s]">', $args['section'], $args['id']);
309 $html .= '<span scope="row" class="bdt-option-label">' . $args['name'] . '</span>';
310 $html .= '</label>';
311
312
313 $html .= sprintf('<input type="%1$s" class="%2$s" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $class, $args['section'], $args['id'], $value, $placeholder);
314
315 $html .= $this->get_field_description($args);
316
317 $html .= '</div>';
318
319 $this->get_control_output($html);
320 }
321
322 /**
323 * Displays a url field for a settings field
324 *
325 * @param array $args settings field args
326 */
327 function callback_url($args) {
328 $this->callback_text($args);
329 }
330
331 /**
332 * Displays a number field for a settings field
333 *
334 * @param array $args settings field args
335 */
336 function callback_number($args) {
337 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
338 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
339 $type = isset($args['type']) ? $args['type'] : 'number';
340 $placeholder = empty($args['placeholder']) ? '' : ' placeholder="' . $args['placeholder'] . '"';
341 $min = ($args['min'] == '') ? '' : ' min="' . $args['min'] . '"';
342 $max = ($args['max'] == '') ? '' : ' max="' . $args['max'] . '"';
343 $step = ($args['step'] == '') ? '' : ' step="' . $args['step'] . '"';
344
345 $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);
346 $html .= $this->get_field_description($args);
347
348 $this->get_control_output($html);
349 }
350
351 /**
352 * Get used widgets.
353 *
354 * @access public
355 * @since 6.0.0
356 *
357 * @return array
358 */
359
360 public static function get_used_widgets_obj() {
361 return UltimateStoreKit_Admin_Settings::get_used_widgets();
362 }
363
364 /**
365 * Get unused widgets.
366 *
367 * @access public
368 * @since 6.0.0
369 *
370 * @return array
371 */
372
373 public static function get_unused_widgets_obj() {
374 return UltimateStoreKit_Admin_Settings::get_unused_widgets();
375 }
376
377 /**
378 * Displays a checkbox for a settings field
379 *
380 * @param array $args settings field args
381 */
382
383 /**
384 * Displays a checkbox for a settings field
385 *
386 * @param array $args settings field args
387 */
388 function callback_checkbox($args) {
389
390 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
391 $plugin_name = isset($args['plugin_name']) ? $args['plugin_name'] : '';
392 $plugin_path = isset($args['plugin_path']) ? $args['plugin_path'] : '';
393 $paid = isset($args['paid']) ? $args['paid'] : '';
394
395
396 $used_widgets = self::get_used_widgets_obj();
397 $widget_name = 'usk-' . $args['id'];
398 $used_widgets_count = 0;
399
400
401 if (isset($used_widgets)) {
402 $used_widgets_count = (in_array($widget_name, array_keys($used_widgets)) ? $used_widgets[$widget_name] : 0);
403 if ($used_widgets_count === 0) {
404 $widget_name = str_replace('_', '-', $widget_name);
405 $used_widgets_count = (in_array($widget_name, array_keys($used_widgets)) ? $used_widgets[$widget_name] : 0);
406 }
407 }
408
409 $widget_using_status = '</span> <br><span class="usk-widget-count-text">Total Used - ' . esc_html($used_widgets_count) . ' </span>';
410
411 // remove counts
412 if (isset($args['id']) && $args['id'] == 'not') {
413 $widget_using_status = '';
414 }
415
416 $html = '';
417
418
419 $html .= '<div class="bdt-option-item-inner">';
420 $html .= '<div class="bdt-grid bdt-grid-collapse bdt-flex bdt-flex-middle">';
421
422 $html .= '<div class="bdt-width-expand bdt-flex-inline bdt-flex-middle">';
423
424 $html .= '<i class="usk-icon-' . esc_attr($args['id']) . '" aria-hidden="true"></i>';
425
426 $html .= sprintf('<label for="bdt_%1$s[%2$s]">', $args['section'], $args['id']);
427 $html .= '<span scope="row" class="bdt-option-label">' . $args['name'] . $widget_using_status;
428 $html .= '</label>';
429
430
431 if ($args['demo_url']) {
432 $html .= '<a href=' . $args['demo_url'] . ' target="_blank" class="bdt-option-demo" bdt-tooltip="View ' . $args['name'] . ' Widget Demo"><i class="usk-icon-preview" aria-hidden="true"></i></a>';
433 }
434 if ($args['video_url']) {
435 $html .= '<a href=' . $args['video_url'] . ' target="_blank" class="bdt-option-video" bdt-tooltip="View ' . $args['name'] . ' Video Tutorial"><i class="usk-icon-tutorial" aria-hidden="true"></i></a>';
436 }
437 $html .= '</div>';
438
439 $html .= '<div class="bdt-width-auto">';
440
441
442
443 // 3rd party widgets
444 if ($plugin_name and $plugin_path) {
445 if ($this->_is_plugin_installed($plugin_name, $plugin_path)) {
446 if (!current_user_can('activate_plugins')) {
447 return;
448 }
449 if (!is_plugin_active($plugin_path)) {
450 $active_link = wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_path . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin_path);
451 $html .= '<a href="' . $active_link . '" class="ultimate-store-kit-3pp-active" bdt-tooltip="Activate the plugin first then you can activate this widget."><span class="dashicons dashicons-admin-plugins"></span></a>';
452 }
453 } else {
454 if ($paid) {
455 $html .= '<a href="' . $paid . '" class="ultimate-store-kit-3pp-download" bdt-tooltip="Download and install plugin first then you can activate this widget."><span class="dashicons dashicons-download"></span></a>';
456 } else {
457 $install_link = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $plugin_name), 'install-plugin_' . $plugin_name);
458 $html .= '<a href="' . $install_link . '" class="ultimate-store-kit-3pp-install" bdt-tooltip="Install the plugin first then you can activate this widget."><span class="dashicons dashicons-download"></span></a>';
459 }
460 }
461
462 if ($this->_is_plugin_installed($plugin_name, $plugin_path) and is_plugin_active($plugin_path)) {
463 $html .= '<fieldset>';
464 $html .= sprintf('<label for="bdt_%1$s[%2$s]">', $args['section'], $args['id']);
465 $html .= sprintf('<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id']);
466 $html .= sprintf('<input type="checkbox" class="checkbox" id="bdt_%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked($value, 'on', false));
467 $html .= '<span class="switch"></span>';
468 $html .= '</label>';
469 $html .= '</fieldset>';
470 }
471 } else { // core widgets
472 $html .= '<fieldset>';
473 $html .= sprintf('<label for="bdt_%1$s[%2$s]">', $args['section'], $args['id']);
474 $html .= sprintf('<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id']);
475 $html .= sprintf('<input type="checkbox" class="checkbox" id="bdt_%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked($value, 'on', false));
476 $html .= '<span class="switch"></span>';
477 $html .= '</label>';
478 $html .= '</fieldset>';
479 }
480
481 $html .= '</div>';
482 $html .= '</div>';
483 $html .= '</div>';
484
485 $this->get_control_output($html);
486 }
487
488 function _is_plugin_installed($plugin, $plugin_path) {
489 $installed_plugins = get_plugins();
490 return isset($installed_plugins[$plugin_path]);
491 }
492
493
494 /**
495 * Displays a multicheckbox for a settings field
496 *
497 * @param array $args settings field args
498 */
499 function callback_multicheck($args) {
500
501 $value = $this->get_option($args['id'], $args['section'], $args['std']);
502 $html = '<fieldset>';
503 $html .= sprintf('<input type="hidden" name="%1$s[%2$s]" value="" />', $args['section'], $args['id']);
504 foreach ($args['options'] as $key => $label) {
505 $checked = isset($value[$key]) ? $value[$key] : '0';
506 $html .= sprintf('<label for="bdt_%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key);
507 $html .= sprintf('<input type="checkbox" class="checkbox" id="bdt_%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));
508 $html .= '<span class="switch"></span>';
509 $html .= sprintf('%1$s</label><br>', $label);
510 }
511
512 $html .= $this->get_field_description($args);
513 $html .= '</fieldset>';
514
515 $this->get_control_output($html);
516 }
517
518 /**
519 * Displays a radio button for a settings field
520 *
521 * @param array $args settings field args
522 */
523 function callback_radio($args) {
524
525 $value = $this->get_option($args['id'], $args['section'], $args['std']);
526 $html = '<fieldset>';
527
528 foreach ($args['options'] as $key => $label) {
529 $html .= sprintf('<label for="bdt_%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key);
530 $html .= sprintf('<input type="radio" class="radio" id="bdt_%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));
531 $html .= sprintf('%1$s</label><br>', $label);
532 }
533
534 $html .= $this->get_field_description($args);
535 $html .= '</fieldset>';
536
537 $this->get_control_output($html);
538 }
539
540 /**
541 * Displays a selectbox for a settings field
542 *
543 * @param array $args settings field args
544 */
545 function callback_select($args) {
546
547 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
548 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
549 $html = sprintf('<select class="%1$s" name="%2$s[%3$s]" id="%2$s[%3$s]">', $size, $args['section'], $args['id']);
550
551 foreach ($args['options'] as $key => $label) {
552 $html .= sprintf('<option value="%s"%s>%s</option>', $key, selected($value, $key, false), $label);
553 }
554
555 $html .= sprintf('</select>');
556 $html .= $this->get_field_description($args);
557
558 $this->get_control_output($html);
559 }
560
561 /**
562 * Displays a textarea for a settings field
563 *
564 * @param array $args settings field args
565 */
566 function callback_textarea($args) {
567
568 $value = esc_textarea($this->get_option($args['id'], $args['section'], $args['std']));
569 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
570 $placeholder = empty($args['placeholder']) ? '' : ' placeholder="' . $args['placeholder'] . '"';
571
572 $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);
573 $html .= $this->get_field_description($args);
574
575 $this->get_control_output($html);
576 }
577
578 /**
579 * Displays the html for a settings field
580 *
581 * @param array $args settings field args
582 * @return string
583 */
584 function callback_html($args) {
585 echo esc_html($args['desc']);
586 }
587
588 /**
589 * Displays a 2 colspan subheading field for a settings field
590 *
591 * @param array $args settings field args
592 */
593 function callback_subheading($args) {
594
595 $html = '<h3 class="setting_subheading column-merge">' . $args['name'] . '</h3>';
596 $html .= $this->get_field_description($args);
597 $html .= '<hr class="setting_separator">';
598
599 $this->get_control_output($html);
600 }
601
602 function callback_start_group($args) {
603
604 $html = '<div class="bdt-option-item-inner bdt-option-group">';
605
606 $html .= sprintf('<label for="bdt_%1$s[%2$s]">', $args['section'], $args['id']);
607 $html .= '<span scope="row" class="bdt-option-label">' . $args['name'] . '</span>';
608 $html .= '</label>';
609
610 if ($args['video_url']) {
611 $html .= '<a href="' . $args['video_url'] . '" target="_blank" class="bdt-option-video" bdt-tooltip="View ' . $args['name'] . ' Video Tutorial"><i class="usk-icon-tutorial" aria-hidden="true"></i></a>';
612 }
613
614 $html .= $this->get_field_description($args);
615
616 $html .= '<div class="bdt-grid" bdt-grid>';
617
618 $this->get_control_output($html);
619 }
620
621 function callback_end_group($args) {
622
623 $html = '</div>';
624 $html .= '</div>';
625
626 $this->get_control_output($html);
627 }
628
629 /**
630 * Displays a 2 colspan separator field for a settings field
631 *
632 * @param array $args settings field args
633 */
634 function callback_separator($args) {
635
636 $html = '<hr class="setting_separator column-merge">';
637 $html .= $this->get_field_description($args);
638
639 $this->get_control_output($html);
640 }
641
642
643 /**
644 * Displays a select box for creating the pages select box
645 *
646 * @param array $args settings field args
647 */
648 function callback_pages($args) {
649
650 $dropdown_args = array(
651 'selected' => esc_attr($this->get_option($args['id'], $args['section'], $args['std'])),
652 'name' => $args['section'] . '[' . $args['id'] . ']',
653 'id' => $args['section'] . '[' . $args['id'] . ']',
654 'echo' => 0
655 );
656 $html = wp_dropdown_pages($dropdown_args);
657 $this->get_control_output($html);
658 }
659
660 /**
661 * Sanitize callback for Settings API
662 *
663 * @return mixed
664 */
665 function sanitize_options($options) {
666
667 if (!$options) {
668 return $options;
669 }
670
671 foreach ($options as $option_slug => $option_value) {
672 $sanitize_callback = $this->get_sanitize_callback($option_slug);
673
674 // If callback is set, call it
675 if ($sanitize_callback) {
676 $options[$option_slug] = call_user_func($sanitize_callback, $option_value);
677 continue;
678 }
679 }
680
681 return $options;
682 }
683
684 /**
685 * Get sanitization callback for given option slug
686 *
687 * @param string $slug option slug
688 *
689 * @return mixed string or bool false
690 */
691 function get_sanitize_callback($slug = '') {
692 if (empty($slug)) {
693 return false;
694 }
695
696 // Iterate over registered fields and see if we can find proper callback
697 foreach ($this->settings_fields as $section => $options) {
698 foreach ($options as $option) {
699 if ($option['name'] != $slug) {
700 continue;
701 }
702
703 // Return the callback name
704 return isset($option['sanitize_callback']) && is_callable($option['sanitize_callback']) ? $option['sanitize_callback'] : false;
705 }
706 }
707
708 return false;
709 }
710
711 /**
712 * Get the value of a settings field
713 *
714 * @param string $option settings field name
715 * @param string $section the section name this field belongs to
716 * @param string $default default text if it's not found
717 * @return string
718 */
719 function get_option($option, $section, $default = '') {
720
721 $options = get_option($section);
722
723 if (isset($options[$option])) {
724 return $options[$option];
725 }
726
727 return $default;
728 }
729
730 /**
731 * Show navigations as tab
732 *
733 * Shows all the settings section labels as tab
734 */
735 /**
736 * Show navigations as tab
737 *
738 * Shows all the settings section labels as tab
739 */
740 function show_navigation() {
741
742 $html = '<div class="bdt-dashboard-navigation">';
743 $html .= '<ul class="bdt-tab" bdt-tab="animation: bdt-animation-slide-bottom-small;connect: .bdt-tab-container;">';
744
745 $html .= sprintf('<li><a href="#%1$s" class="bdt-tab-item" id="bdt-%1$s" data-tab-index="0">%2$s</a></li>', 'ultimate_store_kit_welcome', 'Dashboard');
746
747 $count = 1;
748
749 foreach ($this->settings_sections as $tab) {
750 $html .= sprintf('<li><a href="#%1$s" class="bdt-tab-item" id="bdt-%1$s" data-tab-index="%2$s">%3$s</a></li>', $tab['id'], $count++, $tab['title']);
751 }
752
753 if (true !== _is_usk_pro_activated()) {
754 $html .= sprintf('<li><a href="#%1$s" class="bdt-tab-item" id="bdt-%1$s" data-tab-index="5">%2$s</a></li>', 'pixel_gallery_get_pro', 'Get Pro');
755 }
756
757 // if ( !defined('BDTUSK_LO') ) {
758 // $html .= sprintf('<li><a href="#%1$s" class="bdt-tab-item" id="bdt-%1$s" data-tab-index="%2$s">%3$s</a></li>', 'pixel_gallery_license_settings', $count, 'License');
759 // }
760
761 if ((true == _is_usk_pro_activated()) && !defined('BDTUSK_LO')) {
762 $html .= sprintf('<li><a href="#%1$s" class="bdt-tab-item" id="bdt-%1$s" data-tab-index="5">%2$s</a></li>', 'pixel_gallery_license_settings', 'License');
763 }
764
765 $html .= '</ul>';
766 $html .= '</div>';
767
768 echo $this->get_control_output($html);
769 }
770
771
772
773 /**
774 * Custom sanitizer for option array element sanitize
775 * At first getting the full array then sanitize each element after sanitize them return again to array.
776 * @param array $post_data [description]
777 * @return array [description]
778 */
779 function sanitize_usk_options($post_data) {
780
781 if (isset($post_data)) {
782 foreach ($post_data as $key => $value) {
783 $_options[sanitize_key($key)] = sanitize_key($value);
784 }
785
786 return $_options;
787 }
788 }
789 function ultimate_store_kit_settings_save() {
790
791 if (!check_ajax_referer('ultimate-store-kit-settings-save-nonce')) {
792 wp_send_json_error();
793 }
794
795 if (!current_user_can('manage_options')) {
796 return;
797 }
798
799 $moudle_id = sanitize_key($_POST['id']);
800
801 unset($_POST['id']);
802 $options = $this->sanitize_usk_options($_POST[$moudle_id]);
803
804
805 update_option($moudle_id, $options);
806
807 wp_send_json_success();
808 }
809
810
811 /**
812 * Show the section settings forms
813 *
814 * This function displays every sections in a different form
815 */
816 /**
817 * Show the section settings forms
818 *
819 * This function displays every sections in a different form
820 */
821 function show_forms() {
822 ?>
823
824 <?php $i = 0;
825 foreach ($this->settings_sections as $form) {
826 $i++; ?>
827 <div id="<?php echo esc_attr($form['id']); ?>_page" class="bdt-option-page">
828
829 <div bdt-filter="target: .bdt-options" class="bdt-options-parent" id="bdt-options-parent-<?php echo esc_attr($i); ?>">
830
831
832 <?php if ($form['id'] == 'ultimate_store_kit_active_modules' or $form['id'] == 'ultimate_store_kit_edd_modules' or $form['id'] == 'ultimate_store_kit_general_modules') : ?>
833
834 <div class="bdt-widget-filter-wrapper bdt-grid">
835
836 <div class="bdt-width-expand@l bdt-widget-filter-nav bdt-visible@m">
837 <div class="bdt-flex-inline bdt-flex-middle">
838
839 <div>
840 <ul class="bdt-subnav bdt-subnav-pill bdt-widget-filter bdt-widget-type-content bdt-flex-inline">
841 <li class="bdt-widget-all bdt-active" bdt-filter-control="*"><a href="#">All</a></li>
842 <li class="bdt-widget-free" bdt-filter-control="filter: [data-widget-type='free']; group: data-content-type"><a href="#">Free</a></li>
843 <li class="usk-widget-pro" bdt-filter-control="filter: [data-widget-type='pro']; group: data-content-type"><a href="#">Pro</a></li>
844 </ul>
845 </div>
846
847 <?php if ($form['id'] == 'ultimate_store_kit_active_modules' || $form['id'] == 'ultimate_store_kit_edd_modules' || $form['id'] == 'ultimate_store_kit_general_modules') : ?>
848
849 <div>
850 <button class="bdt-button bdt-button-default" type="button">Filter By Page</button>
851 <div bdt-dropdown="animation: bdt-animation-slide-top-small; duration: 300">
852 <ul class="bdt-nav bdt-subnav-pill bdt-dropdown-nav bdt-widget-filter bdt-widget-content-type">
853 <li class="bdt-widget-new" bdt-filter-control="filter: [data-content-type*='new']; group: data-widget-type"><a href="#">New</a></li>
854 <li class="bdt-widget-single" bdt-filter-control="filter: [data-content-type*='single']; group: data-widget-type"><a href="#">Single</a></li>
855 <li class="bdt-widget-archive" bdt-filter-control="filter: [data-content-type*='archive']; group: data-widget-type"><a href="#">Archive</a></li>
856 <li class="bdt-widget-cart" bdt-filter-control="filter: [data-content-type*='cart']; group: data-widget-type"><a href="#">Cart</a></li>
857 <li class="bdt-widget-checkout" bdt-filter-control="filter: [data-content-type*='checkout']; group: data-widget-type"><a href="#">Checkout</a></li>
858 <li class="bdt-widget-account" bdt-filter-control="filter: [data-content-type*='account']; group: data-widget-type"><a href="#">My Account</a></li>
859 <li class="bdt-widget-others" bdt-filter-control="filter: [data-content-type*='order']; group: data-widget-type"><a href="#">Order/ThankYou</a></li>
860 <li class="bdt-widget-others" bdt-filter-control="filter: [data-content-type*='others']; group: data-widget-type"><a href="#">Others</a></li>
861 <?php if ($form['id'] == 'ultimate_store_kit_edd_modules') : ?>
862 <li class="bdt-widget-ecommerce" bdt-filter-control="filter: [data-content-type*='ecommerce']; group: data-widget-type"><a href="#">eCommerce</a></li>
863 <?php endif; ?>
864
865 </ul>
866 </div>
867 </div>
868
869 <?php if ($form['id'] != 'ultimate_store_kit_elementor_extend' or $form['id'] == 'ultimate_store_kit_edd_modules') : ?>
870
871 <div>
872 <ul class="bdt-subnav bdt-subnav-pill bdt-widget-filter usk-used-unused-widgets bdt-flex-inline">
873 <li class="bdt-widget--" bdt-filter-control="filter: [data-content-type*='usk-used']; group: data-content-type">
874 <a href="#">Used
875 <span class="bdt-badge usk-used-widget"></span>
876 </a>
877 </li>
878 <li class="bdt-widget--" bdt-filter-control="filter: [data-content-type*='usk-unused']; group: data-content-type"><a href="#" bdt-tooltip="Don't need unused widget? Click on the Deactivate All button.">Unused
879 <span class="bdt-badge usk-unused-widget bdt-danger"></span>
880 </a>
881 </li>
882 </ul>
883
884 </div>
885 <?php endif; ?>
886
887 <?php endif; ?>
888 </div>
889 </div>
890
891
892 <div class="bdt-width-auto@l bdt-search-active-wrap bdt-flex bdt-flex-middle bdt-flex-between">
893 <div class="bdt-widget-search">
894 <input data-id="bdt-options-parent-<?php echo esc_attr($i); ?>" onkeyup="filterSearch(this);" bdt-filter-control="" class="bdt-search-input bdt-flex-middle" type="search" placeholder="Search widget..." autofocus>
895 </div>
896
897 <?php //if ($form['id'] == 'ultimate_store_kit_active_modules' or $form['id'] == 'ultimate_store_kit_edd_modules' ) :
898 ?>
899 <div>
900 <ul class="bdt-subnav bdt-subnav-pill bdt-widget-onoff">
901 <li>
902 <a href="#" class="bdt-active-all-widget">
903 <?php esc_html_e('Activate All', 'ultimate-store-kit'); ?>
904 </a>
905 </li>
906 <li>
907 <a href="#" class="bdt-deactive-all-widget">
908 <?php esc_html_e('Deactivate All', 'ultimate-store-kit'); ?>
909 </a>
910 </li>
911 </ul>
912 </div>
913 <?php //endif;
914 ?>
915 </div>
916
917 </div>
918
919 <?php endif; ?>
920
921 <form class="settings-save" method="post" action="admin-ajax.php?action=ultimate_store_kit_settings_save">
922 <input type="hidden" name="id" value="<?php echo esc_attr($form['id']); ?>">
923
924 <?php if (!current_user_can('manage_options')) {
925 return;
926 }
927
928 wp_nonce_field('ultimate-store-kit-settings-save-nonce');
929
930 do_action('wsa_form_top_' . $form['id'], $form);
931
932 $this->do_settings_sections($form['id']);
933
934 do_action('wsa_form_bottom_' . $form['id'], $form);
935
936 ?>
937
938 <div class="ultimate-store-kit-footer-info bdt-container-xlarge">
939
940 <div class="bdt-grid ">
941
942 <div class="bdt-width-auto@s bdt-setting-save-btn">
943
944 <?php if (isset($this->settings_fields[$form['id']])) : ?>
945
946 <button class="bdt-button bdt-button-primary ultimate-store-kit-settings-save-btn" type="submit">Save Settings</button>
947
948 <?php endif; ?>
949
950 </div>
951
952 <div class="bdt-width-expand@s bdt-text-right">
953 <p class="">
954 Ultimate Store Kit plugin made with love by <a target="_blank" href="https://bdthemes.com">BdThemes</a> Team.
955 <br>All rights reserved by <a target="_blank" href="https://bdthemes.com">BdThemes.com</a>.
956 </p>
957 </div>
958 </div>
959
960 </div>
961
962 </form>
963 </div>
964 </div>
965 <?php }
966 }
967 }
968
969 endif;
970