PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.2.3
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.2.3
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / admin / class-settings-api.php

class-settings-api.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.2.3, at admin/class-settings-api.php

1,170 lines 46.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit; // Exit if accessed directly.
5 }
6
7 if (!class_exists('UltimatePostKit_Settings_API')) :
8
9 class UltimatePostKit_Settings_API {
10
11 /**
12 * settings sections array
13 *
14 * @var array
15 */
16 protected $settings_sections = array();
17
18 /**
19 * Settings fields array
20 *
21 * @var array
22 */
23 protected $settings_fields = array();
24
25 public function __construct() {
26 add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
27
28 add_action('wp_ajax_ultimate_post_kit_settings_save', [$this, "ultimate_post_kit_settings_save"]);
29 }
30
31 /**
32 * Enqueue scripts and styles
33 */
34 function admin_enqueue_scripts() {
35 wp_enqueue_script('jquery');
36 }
37
38 /**
39 * Set settings sections
40 *
41 * @param array $sections setting sections array
42 */
43 function set_sections($sections) {
44 $this->settings_sections = $sections;
45
46 return $this;
47 }
48
49 /**
50 * Add a single section
51 *
52 * @param array $section
53 */
54 function add_section($section) {
55 $this->settings_sections[] = $section;
56
57 return $this;
58 }
59
60 /**
61 * Set settings fields
62 *
63 * @param array $fields settings fields array
64 */
65 function set_fields($fields) {
66 $this->settings_fields = $fields;
67
68 return $this;
69 }
70
71 function add_field($section, $field) {
72 $defaults = array(
73 'name' => '',
74 'label' => '',
75 'desc' => '',
76 'type' => 'text'
77 );
78
79 $arg = wp_parse_args($field, $defaults);
80 $this->settings_fields[$section][] = $arg;
81
82 return $this;
83 }
84
85 function do_settings_sections($page) {
86 global $wp_settings_sections, $wp_settings_fields;
87
88 if (!isset($wp_settings_sections[$page])) {
89 return;
90 }
91
92 // $matched_height = ' bdt-grid bdt-height-match="target: > div > .upk-option-item-inner"';
93 $data_settings = '';
94
95 foreach ((array) $wp_settings_sections[$page] as $section) {
96
97 if ($section['id'] == 'ultimate_post_kit_api_settings') {
98 $section_class = ' bdt-grid-small bdt-child-width-1-3@xl';
99 } elseif ($section['id'] == 'ultimate_post_kit_other_settings') {
100 // $data_settings = $matched_height;
101 $section_class = ' bdt-grid-small bdt-child-width-1-3@xl';
102 } else {
103 $section_class = ' bdt-grid-small bdt-child-width-1-4@xl';
104 }
105
106
107
108 if ($section['callback']) {
109 call_user_func($section['callback'], $section);
110 }
111
112 if (!isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']])) {
113 continue;
114 }
115 echo '<div class="upk-options" role="presentation" ' . esc_attr($data_settings) . '>';
116
117 echo '<p class="upk-no-result bdt-text-center bdt-width-1-1 bdt-margin-small-top bdt-h4">'.esc_html__('Ops! Your Searched widget not found! Do you have any idea? If yes, ', 'ultimate-post-kit').'<a href="https://feedback.ultimatepostkit.pro/b/3v2gg80n/feature-requests/idea/new" target="_blank">'.esc_html__('Submit here', 'ultimate-post-kit').'</a></p>';
118
119 $this->do_settings_fields($page, $section['id']);
120
121 echo '</div>';
122 }
123 }
124
125
126 function do_settings_fields($page, $section) {
127 global $wp_settings_fields;
128
129 if (!isset($wp_settings_fields[$page][$section])) {
130 return;
131 }
132
133
134 foreach ((array) $wp_settings_fields[$page][$section] as $field) {
135 $class = '';
136
137 if (!empty($field['args']['class'])) {
138 $class .= ' ' . esc_attr($field['args']['class']);
139 }
140
141 if (!empty($field['args']['widget_type'])) {
142 $class .= ' upk-widget-' . esc_attr($field['args']['widget_type']);
143 }
144
145 if (!empty($field['args']['widget_type']) && 'pro' == $field['args']['widget_type'] && true !== upk_license_validation()) {
146 $class .= ' upk-pro-inactive';
147 }
148
149
150 $used_widgets = self::get_used_widgets_obj();
151 $widget_name = 'upk-' . str_replace(' ', '-', strtolower($field['args']['id']));
152 $used_widgets_count = 0;
153
154 if (isset($used_widgets)) {
155 $used_widgets_count = (in_array($widget_name, array_keys($used_widgets)) ? $used_widgets[$widget_name] : 0);
156 if ($used_widgets_count === 0) {
157 $widget_name = str_replace('_', '-', $widget_name);
158 $used_widgets_count = (in_array($widget_name, array_keys($used_widgets)) ? $used_widgets[$widget_name] : 0);
159 }
160 }
161
162 $widget_used_status = ' upk-used';
163 if ($used_widgets_count === 0) {
164 $widget_used_status = ' upk-unused';
165 }
166
167 $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']) . '"';
168
169
170 if (!empty($field['args']['widget_type']) && 'pro' == $field['args']['widget_type'] && true !== _is_upk_pro_activated()) {
171 $data_type .= ' bdt-tooltip="'.esc_html__('Pro widget only works with Pro version.', 'ultimate-post-kit').'"';
172 }
173
174 echo wp_kses("<div class='upk-option-item {$class} {$widget_used_status}' {$data_type}>", $this->get_allowed_field_html());
175
176 call_user_func($field['callback'], $field['args']);
177
178 echo '</div>';
179 }
180 }
181
182 /**
183 * Initialize and registers the settings sections and fileds to WordPress
184 *
185 * Usually this should be called at `admin_init` hook.
186 *
187 * This function gets the initiated settings sections and fields. Then
188 * registers them to WordPress and ready for use.
189 */
190 function admin_init() {
191 //register settings sections
192 foreach ($this->settings_sections as $section) {
193 if (false == get_option($section['id'])) {
194 add_option($section['id']);
195 }
196
197 if (isset($section['desc']) && !empty($section['desc'])) {
198 $section['desc'] = '<div class="inside">' . $section['desc'] . '</div>';
199 $callback = function () use ($section) {
200 echo wp_kses_post($section['desc']);
201 };
202 } else if (isset($section['callback'])) {
203 $callback = $section['callback'];
204 } else {
205 $callback = null;
206 }
207
208 add_settings_section($section['id'], $section['title'], $callback, $section['id']);
209 }
210
211 //register settings fields
212 foreach ($this->settings_fields as $section => $field) {
213 foreach ($field as $option) {
214
215 $name = $option['name'];
216 $type = isset($option['type']) ? $option['type'] : 'text';
217 $label = isset($option['label']) ? $option['label'] : '';
218 $callback = isset($option['callback']) ? $option['callback'] : array($this, 'callback_' . $type);
219
220 $args = array(
221 'id' => $name,
222 'class' => isset($option['class']) ? 'upk-' . $name . ' ' . $option['class'] : 'upk-' . $name,
223 'label_for' => "upk-{$section}[{$name}]",
224 'desc' => isset($option['desc']) ? $option['desc'] : '',
225 'name' => $label,
226 'section' => $section,
227 'size' => isset($option['size']) ? $option['size'] : null,
228 'options' => isset($option['options']) ? $option['options'] : '',
229 'std' => isset($option['default']) ? $option['default'] : '',
230 'sanitize_callback' => isset($option['sanitize_callback']) ? $option['sanitize_callback'] : '',
231 'type' => $type,
232 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : '',
233 'min' => isset($option['min']) ? $option['min'] : '',
234 'max' => isset($option['max']) ? $option['max'] : '',
235 'step' => isset($option['step']) ? $option['step'] : '',
236 'plugin_name' => !empty($option['plugin_name']) ? $option['plugin_name'] : null,
237 'plugin_path' => !empty($option['plugin_path']) ? $option['plugin_path'] : null,
238 'paid' => !empty($option['paid']) ? $option['paid'] : null,
239 'widget_type' => !empty($option['widget_type']) ? $option['widget_type'] : null,
240 'content_type' => !empty($option['content_type']) ? $option['content_type'] : null,
241 'demo_url' => !empty($option['demo_url']) ? $option['demo_url'] : null,
242 'video_url' => !empty($option['video_url']) ? $option['video_url'] : null,
243 );
244
245 add_settings_field("{$section}[{$name}]", $label, $callback, $section, $section, $args);
246 }
247 }
248
249 // creates our settings in the options table
250 foreach ($this->settings_sections as $section) {
251 register_setting($section['id'], $section['id'], array($this, 'sanitize_options'));
252 }
253 }
254
255 /**
256 * Get field description for display
257 *
258 * @param array $args settings field args
259 */
260 public function get_field_description($args) {
261 if (!empty($args['desc'])) {
262 $desc = sprintf('<p class="description">%s</p>', $args['desc']);
263 } else {
264 $desc = '';
265 }
266
267 return $desc;
268 }
269
270 /**
271 * Allowed HTML for settings-field output. Covers every form control this
272 * class renders so field markup survives wp_kses() intact.
273 *
274 * @return array
275 */
276 public function get_allowed_field_html() {
277 $attr = array(
278 'class' => array(),
279 'id' => array(),
280 'name' => array(),
281 'value' => array(),
282 'type' => array(),
283 'checked' => array(),
284 'selected' => array(),
285 'multiple' => array(),
286 'disabled' => array(),
287 'readonly' => array(),
288 'placeholder' => array(),
289 'min' => array(),
290 'max' => array(),
291 'step' => array(),
292 'rows' => array(),
293 'cols' => array(),
294 'for' => array(),
295 'scope' => array(),
296 'style' => array(),
297 'title' => array(),
298 'target' => array(),
299 'href' => array(),
300 'src' => array(),
301 'rel' => array(),
302 'aria-hidden' => array(),
303 'bdt-tooltip' => array(),
304 'bdt-grid' => array(),
305 'data-default-color' => array(),
306 'data-type' => array(),
307 'data-widget-type' => array(),
308 'data-content-type' => array(),
309 'data-widget-name' => array(),
310 );
311
312 return array(
313 'div' => $attr,
314 'span' => $attr,
315 'label' => $attr,
316 'input' => $attr,
317 'select' => $attr,
318 'option' => $attr,
319 'textarea' => $attr,
320 'fieldset' => $attr,
321 'a' => $attr,
322 'i' => $attr,
323 'p' => $attr,
324 'h3' => $attr,
325 'hr' => $attr,
326 'br' => array(),
327 'strong' => array(),
328 'em' => array(),
329 );
330 }
331
332 /**
333 * Displays a text field for a settings field
334 *
335 * @param array $args settings field args
336 */
337 function callback_text($args) {
338
339 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
340 $class = 'bdt-input';
341 $type = isset($args['type']) ? $args['type'] : 'text';
342 $placeholder = empty($args['placeholder']) ? '' : ' placeholder="' . $args['placeholder'] . '"';
343 $html = '';
344
345
346 $html .= '<div class="upk-option-item-inner">';
347 if ($args['video_url']) {
348 $html .= '<a href="' . $args['video_url'] . '" target="_blank" class="upk-option-video" bdt-tooltip="View ' . $args['name'] . ' Video Tutorial"><i class="upk-icon-tutorial" aria-hidden="true"></i></a>';
349 }
350 $html .= sprintf('<label for="bdt_upk_%1$s[%2$s]">', $args['section'], $args['id']);
351 $html .= '<span scope="row" class="upk-option-label">' . $args['name'] . '</span>';
352 $html .= '</label>';
353
354
355 $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);
356
357 $html .= $this->get_field_description($args);
358
359 $html .= '</div>';
360
361 echo wp_kses($html, $this->get_allowed_field_html());
362 }
363
364 /**
365 * Displays a url field for a settings field
366 *
367 * @param array $args settings field args
368 */
369 function callback_url($args) {
370 $this->callback_text($args);
371 }
372
373 /**
374 * Displays a number field for a settings field
375 *
376 * @param array $args settings field args
377 */
378 function callback_number($args) {
379 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
380 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
381 $type = isset($args['type']) ? $args['type'] : 'number';
382 $placeholder = empty($args['placeholder']) ? '' : ' placeholder="' . $args['placeholder'] . '"';
383 $min = ($args['min'] == '') ? '' : ' min="' . $args['min'] . '"';
384 $max = ($args['max'] == '') ? '' : ' max="' . $args['max'] . '"';
385 $step = ($args['step'] == '') ? '' : ' step="' . $args['step'] . '"';
386
387 $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);
388 $html .= $this->get_field_description($args);
389
390 echo wp_kses($html, $this->get_allowed_field_html());
391 }
392
393 /**
394 * Get used widgets.
395 *
396 * @access public
397 * @since 6.0.0
398 *
399 * @return array
400 */
401
402 public static function get_used_widgets_obj() {
403 return UltimatePostKit_Admin_Settings::get_used_widgets();
404 }
405
406 /**
407 * Get unused widgets.
408 *
409 * @access public
410 * @since 6.0.0
411 *
412 * @return array
413 */
414
415 public static function get_unused_widgets_obj() {
416 return UltimatePostKit_Admin_Settings::get_unused_widgets();
417 }
418
419 /**
420 * Displays a checkbox for a settings field
421 *
422 * @param array $args settings field args
423 */
424 function callback_checkbox($args) {
425
426 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
427 $plugin_name = isset($args['plugin_name']) ? $args['plugin_name'] : '';
428 $plugin_path = isset($args['plugin_path']) ? $args['plugin_path'] : '';
429 $paid = isset($args['paid']) ? $args['paid'] : '';
430
431 $parent_class = isset($args['ep_parent_switcher']) ? ' upk-feature-option-parent' : '';
432
433 $used_widgets = self::get_used_widgets_obj();
434 $widget_name = 'bdt-' . $args['id'];
435 $used_widgets_count = 0;
436
437
438 if (isset($used_widgets)) {
439 $used_widgets_count = (in_array($widget_name, array_keys($used_widgets)) ? $used_widgets[$widget_name] : 0);
440 if ($used_widgets_count === 0) {
441 $widget_name = str_replace('_', '-', $widget_name);
442 $used_widgets_count = (in_array($widget_name, array_keys($used_widgets)) ? $used_widgets[$widget_name] : 0);
443 }
444 }
445
446 $html = '';
447
448 $html .= '<div class="upk-option-item-inner">';
449 $html .= '<div class="bdt-grid bdt-grid-collapse bdt-flex bdt-flex-middle">';
450
451 $html .= '<div class="bdt-width-expand bdt-flex-inline bdt-flex-middle">';
452
453
454 $html .= '<i class="upk-icon-' . esc_attr($args['id']) . '" aria-hidden="true"></i>';
455 $html .= '<div class="upk-option-label-wrap">';
456 $html .= sprintf('<label for="bdt_upk_%1$s[%2$s]">', $args['section'], $args['id']);
457 $html .= '<span scope="row" class="upk-option-label">' . $args['name'] . '</span>';
458 $html .= '</label>';
459
460 $html .= '<div class="upk-option-links">';
461 if ($args['demo_url']) {
462 /* translators: %s: widget name */
463 $demo_title = sprintf(esc_html__('View %s Widget Demo', 'ultimate-post-kit'), $args['name']);
464 $html .= '<a href=' . $args['demo_url'] . ' target="_blank" class="upk-option-demo" title="' . $demo_title . '">' . esc_html__('Demo', 'ultimate-post-kit') . '<i class="upk-icon-preview" aria-hidden="true"></i></a>';
465 }
466 if ($args['video_url']) {
467 $html .= '<a href=' . $args['video_url'] . ' target="_blank" class="upk-option-video" title="View ' . $args['name'] . ' Video Tutorial">Video<i class="upk-icon-tutorial" aria-hidden="true"></i></a>';
468 }
469 $html .= '</div>';
470 $html .= '</div>';
471 $html .= '</div>';
472
473 $html .= '<div class="bdt-width-auto">';
474
475
476
477 // 3rd party widgets
478 if ($plugin_name and $plugin_path) {
479
480 if ($this->_is_plugin_installed($plugin_name, $plugin_path)) {
481 if (!current_user_can('activate_plugins')) {
482 return;
483 }
484 if (!is_plugin_active($plugin_path)) {
485 $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);
486 $html .= '<a href="' . $active_link . '" class="ultimate-post-kit-3pp-active" bdt-tooltip="' . esc_html__('Activate the plugin first then you can activate this widget.', 'ultimate-post-kit') . '"><span class="dashicons dashicons-admin-plugins"></span></a>';
487 }
488 } else {
489 if ($paid) {
490 $html .= '<a href="' . $paid . '" class="ultimate-post-kit-3pp-download" bdt-tooltip="' . esc_html__('Download and install plugin first then you can activate this widget.', 'ultimate-post-kit') . '"><span class="dashicons dashicons-download"></span></a>';
491 } else {
492 $install_link = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $plugin_name), 'install-plugin_' . $plugin_name);
493 $html .= '<a href="' . $install_link . '" class="ultimate-post-kit-3pp-install" bdt-tooltip="' . esc_html__('Install the plugin first then you can activate this widget.', 'ultimate-post-kit') . '"><span class="dashicons dashicons-download"></span></a>';
494 }
495 }
496 if ($this->_is_plugin_installed($plugin_name, $plugin_path) and is_plugin_active($plugin_path)) {
497
498 $html .= '<fieldset>';
499 $html .= sprintf('<label for="bdt_upk_%1$s[%2$s]">', $args['section'], $args['id']);
500 $html .= sprintf('<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id']);
501 $html .= sprintf('<input type="checkbox" class="checkbox' . $parent_class . '" id="bdt_upk_%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked($value, 'on', false));
502 $html .= '<span class="switch"></span>';
503 $html .= '</label>';
504 $html .= '</fieldset>';
505 }
506 } else { // core widgets
507
508 $html .= '<fieldset>';
509 $html .= sprintf('<label for="bdt_upk_%1$s[%2$s]">', $args['section'], $args['id']);
510 $html .= sprintf('<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id']);
511 $html .= sprintf('<input type="checkbox" class="checkbox" id="bdt_upk_%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked($value, 'on', false));
512 $html .= '<span class="switch"></span>';
513 $html .= '</label>';
514 $html .= '</fieldset>';
515 }
516
517 $html .= '</div>';
518 $html .= '</div>';
519 $html .= '</div>';
520
521 echo wp_kses($html, array(
522 'div' => array(
523 'class' => array(),
524 ),
525 'span' => array(
526 'class' => array(),
527 ),
528 'label' => array(
529 'for' => array(),
530 ),
531 'input' => array(
532 'type' => array(),
533 'class' => array(),
534 'id' => array(),
535 'name' => array(),
536 'value' => array(),
537 'checked' => array(),
538 ),
539 'i' => array(
540 'class' => array(),
541 'aria-hidden' => array(),
542 ),
543 'a' => array(
544 'href' => array(),
545 'target' => array(),
546 'class' => array(),
547 'bdt-tooltip' => array(),
548 ),
549 'fieldset' => array(),
550 ));
551 }
552
553 function _is_plugin_installed($plugin, $plugin_path) {
554 $installed_plugins = get_plugins();
555 return isset($installed_plugins[$plugin_path]);
556 }
557
558
559 /**
560 * Displays a multicheckbox for a settings field
561 *
562 * @param array $args settings field args
563 */
564 function callback_multicheck($args) {
565
566 $value = $this->get_option($args['id'], $args['section'], $args['std']);
567 $html = '<fieldset>';
568 $html .= sprintf('<input type="hidden" name="%1$s[%2$s]" value="" />', $args['section'], $args['id']);
569 foreach ($args['options'] as $key => $label) {
570 $checked = isset($value[$key]) ? $value[$key] : '0';
571 $html .= sprintf('<label for="bdt_upk_%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key);
572 $html .= sprintf('<input type="checkbox" class="checkbox" id="bdt_upk_%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));
573 $html .= '<span class="switch"></span>';
574 $html .= sprintf('%1$s</label><br>', $label);
575 }
576
577 $html .= $this->get_field_description($args);
578 $html .= '</fieldset>';
579
580 echo wp_kses($html, $this->get_allowed_field_html());
581 }
582
583 /**
584 * Displays a radio button for a settings field
585 *
586 * @param array $args settings field args
587 */
588 function callback_radio($args) {
589
590 $value = $this->get_option($args['id'], $args['section'], $args['std']);
591 $html = '<fieldset>';
592
593 foreach ($args['options'] as $key => $label) {
594 $html .= sprintf('<label for="bdt_upk_%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key);
595 $html .= sprintf('<input type="radio" class="radio" id="bdt_upk_%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));
596 $html .= sprintf('%1$s</label><br>', $label);
597 }
598
599 $html .= $this->get_field_description($args);
600 $html .= '</fieldset>';
601
602 echo wp_kses($html, $this->get_allowed_field_html());
603 }
604
605 /**
606 * Displays a selectbox for a settings field
607 *
608 * @param array $args settings field args
609 */
610 function callback_select($args) {
611
612 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
613 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
614 $html = sprintf('<select class="%1$s" name="%2$s[%3$s]" id="%2$s[%3$s]">', $size, $args['section'], $args['id']);
615
616 foreach ($args['options'] as $key => $label) {
617 $html .= sprintf('<option value="%s"%s>%s</option>', $key, selected($value, $key, false), $label);
618 }
619
620 $html .= sprintf('</select>');
621 $html .= $this->get_field_description($args);
622
623 echo wp_kses($html, $this->get_allowed_field_html());
624 }
625
626 /**
627 * Displays a textarea for a settings field
628 *
629 * @param array $args settings field args
630 */
631 function callback_textarea($args) {
632
633 $value = esc_textarea($this->get_option($args['id'], $args['section'], $args['std']));
634 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
635 $placeholder = empty($args['placeholder']) ? '' : ' placeholder="' . $args['placeholder'] . '"';
636
637 $html = '';
638 $html .= sprintf('<label for="bdt_upk_%1$s[%2$s]">', $args['section'], $args['id']);
639 $html .= '<span scope="row" class="upk-option-label">' . $args['name'] . '</span>';
640 $html .= '</label>';
641
642 $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);
643 $html .= $this->get_field_description($args);
644
645 echo wp_kses($html, $this->get_allowed_field_html());
646 }
647
648 /**
649 * Displays the html for a settings field
650 *
651 * @param array $args settings field args
652 * @return string
653 */
654 function callback_html($args) {
655 echo wp_kses($args['desc'], $this->get_allowed_field_html());
656 }
657
658 /**
659 * Displays a file upload field for a settings field
660 *
661 * @param array $args settings field args
662 */
663 function callback_file($args) {
664
665 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
666 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
667 $id = $args['section'] . '[' . $args['id'] . ']';
668 $label = isset($args['options']['button_label']) ? $args['options']['button_label'] : __('Choose File', 'ultimate-post-kit');
669
670 $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);
671 $html .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
672 $html .= $this->get_field_description($args);
673
674 echo wp_kses($html, $this->get_allowed_field_html());
675 }
676
677 /**
678 * Displays a password field for a settings field
679 *
680 * @param array $args settings field args
681 */
682 function callback_password($args) {
683
684 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
685 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
686
687 $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);
688 $html .= $this->get_field_description($args);
689
690 echo wp_kses($html, $this->get_allowed_field_html());
691 }
692
693 /**
694 * Displays a color picker field for a settings field
695 *
696 * @param array $args settings field args
697 */
698 function callback_color($args) {
699
700 $value = esc_attr($this->get_option($args['id'], $args['section'], $args['std']));
701 $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
702
703 $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']);
704 $html .= $this->get_field_description($args);
705
706 echo wp_kses($html, $this->get_allowed_field_html());
707 }
708
709 /**
710 * Displays a 2 colspan subheading field for a settings field
711 *
712 * @param array $args settings field args
713 */
714 function callback_subheading($args) {
715
716 $html = '<h3 class="setting_subheading column-merge">' . $args['name'] . '</h3>';
717 $html .= $this->get_field_description($args);
718 $html .= '<hr class="setting_separator">';
719
720 echo wp_kses($html, $this->get_allowed_field_html());
721 }
722
723 function callback_start_group($args) {
724
725 $html = '<div class="upk-option-item-inner upk-option-group">';
726
727 $html .= sprintf('<label for="bdt_upk_%1$s[%2$s]">', $args['section'], $args['id']);
728 $html .= '<span scope="row" class="upk-option-label">' . $args['name'] . '</span>';
729 $html .= '</label>';
730
731 if ($args['video_url']) {
732 $html .= '<a href="' . $args['video_url'] . '" target="_blank" class="upk-option-video" bdt-tooltip="View ' . $args['name'] . ' Video Tutorial"><i class="upk-icon-tutorial" aria-hidden="true"></i></a>';
733 }
734
735 $html .= $this->get_field_description($args);
736
737 $html .= '<div class="bdt-grid" bdt-grid>';
738
739 echo wp_kses($html, $this->get_allowed_field_html());
740 }
741
742 function callback_end_group($args) {
743
744 $html = '</div>';
745 $html .= '</div>';
746
747 echo wp_kses($html, $this->get_allowed_field_html());
748 }
749
750 /**
751 * Displays a 2 colspan separator field for a settings field
752 *
753 * @param array $args settings field args
754 */
755 function callback_separator($args) {
756
757 $html = '<hr class="setting_separator column-merge">';
758 $html .= $this->get_field_description($args);
759
760
761 echo wp_kses($html, $this->get_allowed_field_html());
762 }
763
764
765 /**
766 * Displays a select box for creating the pages select box
767 *
768 * @param array $args settings field args
769 */
770 function callback_pages($args) {
771
772 $dropdown_args = array(
773 'selected' => esc_attr($this->get_option($args['id'], $args['section'], $args['std'])),
774 'name' => $args['section'] . '[' . $args['id'] . ']',
775 'id' => $args['section'] . '[' . $args['id'] . ']',
776 'echo' => 0
777 );
778 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- 'echo' => 0 makes wp_dropdown_pages() return (not print) the markup, which is escaped via wp_kses() below.
779 $html = wp_dropdown_pages($dropdown_args);
780 echo wp_kses($html, $this->get_allowed_field_html());
781 }
782
783 /**
784 * Sanitize callback for Settings API
785 *
786 * @return mixed
787 */
788 function sanitize_options($options) {
789
790 if (!$options) {
791 return $options;
792 }
793
794 foreach ($options as $option_slug => $option_value) {
795 $sanitize_callback = $this->get_sanitize_callback($option_slug);
796
797 // If callback is set, call it
798 if ($sanitize_callback) {
799 $options[$option_slug] = call_user_func($sanitize_callback, $option_value);
800 continue;
801 }
802 }
803
804 return $options;
805 }
806
807 /**
808 * Get sanitization callback for given option slug
809 *
810 * @param string $slug option slug
811 *
812 * @return mixed string or bool false
813 */
814 function get_sanitize_callback($slug = '') {
815 if (empty($slug)) {
816 return false;
817 }
818
819 // Iterate over registered fields and see if we can find proper callback
820 foreach ($this->settings_fields as $section => $options) {
821 foreach ($options as $option) {
822 if ($option['name'] != $slug) {
823 continue;
824 }
825
826 // Return the callback name
827 return isset($option['sanitize_callback']) && is_callable($option['sanitize_callback']) ? $option['sanitize_callback'] : false;
828 }
829 }
830
831 return false;
832 }
833
834 /**
835 * Get the value of a settings field
836 *
837 * @param string $option settings field name
838 * @param string $section the section name this field belongs to
839 * @param string $default default text if it's not found
840 * @return string
841 */
842 function get_option($option, $section, $default = '') {
843
844 $options = get_option($section);
845
846 if (isset($options[$option])) {
847 return $options[$option];
848 }
849
850 return $default;
851 }
852
853 /**
854 * Show navigations as tab
855 *
856 * Shows all the settings section labels as tab
857 */
858 function show_navigation() {
859 $html = '<div class="bdt-dashboard-navigation">';
860 $html .= '<ul class="bdt-tab bdt-flex-column" bdt-tab="animation: bdt-animation-slide-bottom-small;connect: .bdt-tab-container;">';
861
862 // Dashboard - always first
863 $html .= sprintf('<li><a href="#%1$s" class="bdt-tab-item" id="bdt-%1$s" data-tab-index="0"><i class="dashicons dashicons-admin-home"></i>%2$s</a></li>', 'ultimate_post_kit_welcome', esc_html__('Dashboard', 'ultimate-post-kit'));
864
865 $count = 1;
866
867 // Get all sections including manually created ones
868 $all_sections = $this->get_all_sections();
869
870 foreach ($all_sections as $tab) {
871 $icon = isset($tab['icon']) ? $tab['icon'] : 'dashicons dashicons-screenoptions';
872 $html .= sprintf('<li><a href="#%1$s" class="bdt-tab-item" id="bdt-%1$s" data-tab-index="%2$s"><i class="%4$s"></i>%3$s</a></li>', $tab['id'], $count++, $tab['title'], $icon);
873 }
874
875 // License section
876 $license_wl_status = UltimatePostKit_Admin_Settings::license_wl_status();
877
878 if (!defined('BDTUPK_LO') || false == $license_wl_status) {
879 $html .= sprintf('<li><a href="#%1$s" class="bdt-tab-item" id="bdt-%1$s" data-tab-index="%2$s"><i class="dashicons dashicons-admin-network"></i>%3$s</a></li>', 'ultimate_post_kit_license_settings', $count, esc_html__('License', 'ultimate-post-kit'));
880 }
881
882 $html .= '</ul>';
883 $html .= '</div>';
884
885 echo wp_kses($html, array(
886 'div' => array(
887 'class' => true,
888 ),
889 'ul' => array(
890 'class' => true,
891 'bdt-tab' => true,
892 ),
893 'li' => array(
894 'class' => true,
895 ),
896 'a' => array(
897 'href' => true,
898 'class' => true,
899 'id' => true,
900 'data-tab-index' => true,
901 ),
902 'i' => array(
903 'class' => true,
904 )
905 ));
906 }
907
908 function ultimate_post_kit_settings_save() {
909
910 if (!check_ajax_referer('ultimate-post-kit-settings-save-nonce')) {
911 wp_send_json_error();
912 }
913
914 if (!current_user_can('manage_options')) {
915 return;
916 }
917
918 $moudle_id = sanitize_text_field($_POST['id']);
919
920 unset($_POST['id']);
921
922 if (isset($_POST[$moudle_id])) {
923 update_option($moudle_id, $_POST[$moudle_id]);
924 }
925
926 wp_send_json_success();
927 }
928
929 /**
930 * Get all sections including manually created content pages
931 */
932 private function get_all_sections() {
933 // Start with the settings sections that have forms
934 $all_sections = $this->settings_sections;
935
936 // Add manually created content sections that don't have settings forms
937 $content_only_sections = [
938 [
939 'id' => 'ultimate_post_kit_extra_options',
940 'title' => esc_html__('Extra Options', 'ultimate-post-kit'),
941 'icon' => 'dashicons dashicons-smiley',
942 ],
943 [
944 'id' => 'ultimate_post_kit_analytics_system_req',
945 'title' => esc_html__('System Status', 'ultimate-post-kit'),
946 'icon' => 'dashicons dashicons-chart-bar',
947 ],
948 [
949 'id' => 'ultimate_post_kit_other_plugins',
950 'title' => esc_html__('Other Plugins', 'ultimate-post-kit'),
951 'icon' => 'dashicons dashicons-admin-plugins',
952 ],
953 // [
954 // 'id' => 'ultimate_post_kit_affiliate',
955 // 'title' => esc_html__('Get Up to 60%', 'ultimate-post-kit'),
956 // 'icon' => 'dashicons dashicons-money-alt',
957 // ],
958 ];
959
960 if (true == _is_upk_pro_activated()) {
961 $content_only_sections[] = [
962 'id' => 'ultimate_post_kit_rollback_version',
963 'title' => esc_html__('Rollback Version', 'ultimate-post-kit'),
964 'icon' => 'dashicons dashicons-update',
965 ];
966 }
967
968 // Check if each content section exists in settings sections, if not add it
969 foreach ($content_only_sections as $content_section) {
970 $exists = false;
971 foreach ($all_sections as $existing_section) {
972 if ($existing_section['id'] === $content_section['id']) {
973 $exists = true;
974 break;
975 }
976 }
977 if (!$exists) {
978 $all_sections[] = $content_section;
979 }
980 }
981
982 return $all_sections;
983 }
984
985 /**
986 * Show the section settings forms
987 *
988 * This function displays every sections in a different form
989 */
990 function show_forms() {
991 ?>
992
993 <?php $i = 0;
994 foreach ($this->settings_sections as $form) {
995 $i++; ?>
996 <div id="<?php echo esc_attr($form['id']); ?>_page" class="upk-option-page">
997
998 <div bdt-filter="target: .upk-options" class="upk-options-parent" id="upk-options-parent-<?php echo esc_attr($i); ?>">
999
1000
1001 <?php if ($form['id'] == 'ultimate_post_kit_active_modules' or $form['id'] == 'ultimate_post_kit_elementor_extend'): ?>
1002
1003 <div class="bdt-widget-filter-wrapper bdt-flex bdt-flex-column bdt-flex-wrap"
1004 bdt-sticky="end: !.upk-dashboard-container; offset: 115; animation: bdt-animation-slide-top-small; duration: 300">
1005
1006 <!-- Filter Shape Elements -->
1007 <div class="upk-filter-elements">
1008 <span class="upk-filter-element upk-filter-circle"></span>
1009 <span class="upk-filter-element upk-filter-dots"></span>
1010 <span class="upk-filter-element upk-filter-wave"></span>
1011 <span class="upk-filter-element upk-filter-hexagon"></span>
1012 <span class="upk-filter-element upk-filter-zigzag"></span>
1013 </div>
1014
1015 <div class="bdt-widget-filter-header">
1016
1017 <div class="bdt-flex bdt-flex-wrap">
1018
1019 <div class="bdt-width-expand@l upk-widget-filter-nav bdt-visible@l">
1020 <div class="bdt-flex-inline bdt-flex-middle">
1021
1022 <div>
1023 <ul
1024 class="bdt-subnav bdt-subnav-pill upk-widget-filter bdt-widget-type-content bdt-flex-inline">
1025 <li class="upk-widget-all bdt-active" bdt-filter-control="*"><a
1026 href="#"><?php esc_html_e('All', 'ultimate-post-kit'); ?></a></li>
1027 <li class="upk-widget-free"
1028 bdt-filter-control="filter: [data-widget-type='free']; group: data-content-type">
1029 <a href="#"><?php esc_html_e('Free', 'ultimate-post-kit'); ?></a>
1030 </li>
1031 <li class="upk-widget-pro"
1032 bdt-filter-control="filter: [data-widget-type='pro']; group: data-content-type">
1033 <a href="#"><?php esc_html_e('Pro', 'ultimate-post-kit'); ?></a>
1034 </li>
1035
1036 </ul>
1037 </div>
1038
1039 <?php if ($form['id'] == 'ultimate_post_kit_active_modules' or $form['id'] == 'ultimate_post_kit_third_party_widget'): ?>
1040
1041
1042 <?php if ($form['id'] != 'ultimate_post_kit_elementor_extend' or $form['id'] == 'ultimate_post_kit_third_party_widget'): ?>
1043
1044 <div>
1045 <ul
1046 class="bdt-subnav bdt-subnav-pill upk-widget-filter upk-used-unused-widgets bdt-flex-inline ">
1047 <li class="upk-widget--"
1048 bdt-filter-control="filter: [data-content-type*='upk-used']; group: data-content-type">
1049 <a href="#"><?php esc_html_e('Used', 'ultimate-post-kit'); ?>
1050 <span class="bdt-badge upk-used-widget"></span>
1051 </a>
1052 </li>
1053 <li class="upk-widget--"
1054 bdt-filter-control="filter: [data-content-type*='upk-unused']; group: data-content-type">
1055 <a href="#"
1056 bdt-tooltip="<?php esc_html_e('Don\'t need unused widget? Click on the Deactivate All button.', 'ultimate-post-kit'); ?>"><?php esc_html_e('Unused', 'ultimate-post-kit'); ?>
1057 <span class="bdt-badge upk-unused-widget bdt-danger"></span>
1058 </a>
1059 </li>
1060 </ul>
1061
1062 </div>
1063 <?php endif; ?>
1064
1065 <?php endif; ?>
1066 </div>
1067 </div>
1068
1069
1070 <div class="bdt-width-auto@l bdt-search-active-wrap bdt-flex bdt-flex-middle bdt-flex-between">
1071 <div class="bdt-widget-search">
1072 <input data-id="upk-options-parent-<?php echo esc_attr($i); ?>" onkeyup="filterSearch(this);"
1073 bdt-filter-control="" class="bdt-search-input bdt-flex-middle" type="search"
1074 placeholder="<?php esc_html_e('Search widget...', 'ultimate-post-kit'); ?>"
1075 autofocus>
1076 </div>
1077
1078 <div>
1079 <ul class="bdt-subnav bdt-subnav-pill upk-widget-onoff">
1080 <li>
1081 <a href="#" class="upk-active-all-widget">
1082 <?php esc_html_e('Activate All', 'ultimate-post-kit'); ?>
1083 </a>
1084 </li>
1085 <li>
1086 <a href="#" class="upk-deactive-all-widget">
1087 <?php esc_html_e('Deactivate All', 'ultimate-post-kit'); ?>
1088 </a>
1089 </li>
1090 </ul>
1091 </div>
1092 </div>
1093 </div>
1094
1095 <?php if ($form['id'] == 'ultimate_post_kit_active_modules'): ?>
1096 <div class="upk-content-type-filter bdt-margin-top">
1097 <div class="bdt-flex bdt-flex-wrap bdt-flex-middle bdt-visible@l">
1098 <div class="upk-filter-by-text bdt-visible@xl">
1099 <?php esc_html_e('Filter By: ', 'ultimate-post-kit'); ?>
1100 </div>
1101 <ul class="bdt-nav xbdt-subnav-pill xbdt-dropdown-nav upk-widget-filter upk-widget-content-type bdt-flex bdt-flex-wrap ">
1102 <li class="upk-widget-new" bdt-filter-control="filter: [data-content-type*='new']; group: data-widget-type">
1103 <a href="#"><?php esc_html_e('New', 'ultimate-post-kit'); ?></a>
1104 </li>
1105 <li class="upk-widget-grid" bdt-filter-control="filter: [data-content-type*='grid']; group: data-widget-type">
1106 <a href="#"><?php esc_html_e('Grid', 'ultimate-post-kit'); ?></a>
1107 </li>
1108 <li class="upk-widget-list" bdt-filter-control="filter: [data-content-type*='list']; group: data-widget-type">
1109 <a href="#"><?php esc_html_e('List', 'ultimate-post-kit'); ?></a>
1110 </li>
1111 <li class="upk-widget-carousel" bdt-filter-control="filter: [data-content-type*='carousel']; group: data-widget-type">
1112 <a href="#"><?php esc_html_e('Carousel', 'ultimate-post-kit'); ?></a>
1113 </li>
1114 <li class="upk-widget-slider" bdt-filter-control="filter: [data-content-type*='slider']; group: data-widget-type">
1115 <a href="#"><?php esc_html_e('Slider', 'ultimate-post-kit'); ?></a>
1116 </li>
1117 <li class="upk-widget-tabs" bdt-filter-control="filter: [data-content-type*='tabs']; group: data-widget-type">
1118 <a href="#"><?php esc_html_e('Tabs', 'ultimate-post-kit'); ?></a>
1119 </li>
1120 <li class="upk-widget-timeline" bdt-filter-control="filter: [data-content-type*='timeline']; group: data-widget-type">
1121 <a href="#"><?php esc_html_e('Timeline', 'ultimate-post-kit'); ?></a>
1122 </li>
1123 <li class="upk-widget-template-builder" bdt-filter-control="filter: [data-content-type*='template-builder']; group: data-widget-type">
1124 <a href="#"><?php esc_html_e('Template Builder', 'ultimate-post-kit'); ?></a>
1125 </li>
1126 <li class="upk-widget-loop" bdt-filter-control="filter: [data-content-type*='loop']; group: data-widget-type">
1127 <a href="#"><?php esc_html_e('Loop Builder', 'ultimate-post-kit'); ?></a>
1128 </li>
1129 <li class="upk-widget-others" bdt-filter-control="filter: [data-content-type*='others']; group: data-widget-type">
1130 <a href="#"><?php esc_html_e('Others', 'ultimate-post-kit'); ?></a>
1131 </li>
1132 </ul>
1133 </div>
1134 </div>
1135 <?php endif; ?>
1136
1137 </div>
1138
1139 </div>
1140
1141 <?php endif; ?>
1142
1143 <form class="settings-save" method="post" action="admin-ajax.php?action=ultimate_post_kit_settings_save">
1144 <input type="hidden" name="id" value="<?php echo esc_attr($form['id']); ?>">
1145
1146 <?php
1147
1148 if (!current_user_can('manage_options')) {
1149 return;
1150 }
1151
1152 wp_nonce_field('ultimate-post-kit-settings-save-nonce');
1153
1154 do_action('wsa_form_top_' . $form['id'], $form);
1155
1156 $this->do_settings_sections($form['id']);
1157
1158 do_action('wsa_form_bottom_' . $form['id'], $form);
1159
1160 ?>
1161
1162 </form>
1163 </div>
1164 </div>
1165 <?php }
1166 }
1167 }
1168
1169 endif;
1170