PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 1.6.2
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v1.6.2
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.6.2, at admin/class-settings-api.php

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