PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.3.2
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.3.2
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Admin / Framework / Classes / Darkify.php

Darkify.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.3.2, at src/Admin/Framework/Classes/Darkify.php

774 lines 25.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ThemeAtelier\Darkify\Admin\Framework\Classes;
4
5 if (! defined('ABSPATH')) {
6 die;
7 } // Cannot access directly.
8 /**
9 *
10 * Setup Class
11 *
12 * @since 1.0.0
13 * @version 1.0.0
14 *
15 */
16 if (! class_exists('Darkify')) {
17 class Darkify
18 {
19
20 // Default constants
21 public static $premium = true;
22 public static $version = '2.3.0';
23 public static $dir = '';
24 public static $url = '';
25 public static $css = '';
26 public static $file = '';
27 public static $enqueue = false;
28 public static $webfonts = array();
29 public static $subsets = array();
30 public static $inited = array();
31 public static $fields = array();
32 public static $args = array(
33 'admin_options' => array(),
34 'customize_options' => array(),
35 'metabox_options' => array(),
36 'nav_menu_options' => array(),
37 'profile_options' => array(),
38 'taxonomy_options' => array(),
39 'widget_options' => array(),
40 'comment_options' => array(),
41 'shortcode_options' => array(),
42 );
43
44 // Shortcode instances
45 public static $shortcode_instances = array();
46
47 private static $instance = null;
48
49 public static function init($file = __FILE__, $premium = true)
50 {
51
52 // Set file constant
53 self::$file = $file;
54
55 // Set file constant
56 self::$premium = $premium;
57
58 // Set constants
59 self::constants();
60
61 // Include files
62 self::includes();
63
64 if (is_null(self::$instance)) {
65 self::$instance = new self();
66 }
67
68 return self::$instance;
69 }
70
71 // Initalize
72 public function __construct()
73 {
74
75 // Init action
76 do_action('darkify_init');
77
78 add_action('after_setup_theme', array('ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify', 'setup'));
79 add_action('init', array('ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify', 'setup'));
80 add_action('switch_theme', array('ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify', 'setup'));
81 add_action('admin_enqueue_scripts', array('ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify', 'add_admin_enqueue_scripts'));
82 add_action('wp_enqueue_scripts', array('ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify', 'add_typography_enqueue_styles'), 80);
83 add_action('wp_head', array('ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify', 'add_custom_css'), 80);
84 add_filter('admin_body_class', array('ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify', 'add_admin_body_class'));
85 }
86
87 // Setup frameworks
88 public static function setup()
89 {
90
91 // Welcome
92 self::include_plugin_file('views/welcome.php');
93
94 // Setup admin option framework
95 $params = array();
96 if (class_exists('DarkifyOptions') && ! empty(self::$args['admin_options'])) {
97 foreach (self::$args['admin_options'] as $key => $value) {
98 if (! empty(self::$args['sections'][$key]) && ! isset(self::$inited[$key])) {
99
100 $params['args'] = $value;
101 $params['sections'] = self::$args['sections'][$key];
102 self::$inited[$key] = true;
103
104 \DarkifyOptions::instance($key, $params);
105
106 if (! empty($value['show_in_customizer'])) {
107 $value['output_css'] = false;
108 $value['enqueue_webfont'] = false;
109 self::$args['customize_options'][$key] = $value;
110 self::$inited[$key] = null;
111 }
112 }
113 }
114 }
115
116 // Setup customize option framework
117 $params = array();
118 if (class_exists('DarkifyCustomizeOptions') && ! empty(self::$args['customize_options'])) {
119 foreach (self::$args['customize_options'] as $key => $value) {
120 if (! empty(self::$args['sections'][$key]) && ! isset(self::$inited[$key])) {
121
122 $params['args'] = $value;
123 $params['sections'] = self::$args['sections'][$key];
124 self::$inited[$key] = true;
125
126 DarkifyCustomizeOptions::instance($key, $params);
127 }
128 }
129 }
130
131 // Setup metabox option framework
132 $params = array();
133 if (class_exists('DarkifyMetabox') && ! empty(self::$args['metabox_options'])) {
134 foreach (self::$args['metabox_options'] as $key => $value) {
135 if (! empty(self::$args['sections'][$key]) && ! isset(self::$inited[$key])) {
136
137 $params['args'] = $value;
138 $params['sections'] = self::$args['sections'][$key];
139 self::$inited[$key] = true;
140
141 DarkifyMetabox::instance($key, $params);
142 }
143 }
144 }
145
146 // Setup nav menu option framework
147 $params = array();
148 if (class_exists('DarkifyNavMenuOptions') && ! empty(self::$args['nav_menu_options'])) {
149 foreach (self::$args['nav_menu_options'] as $key => $value) {
150 if (! empty(self::$args['sections'][$key]) && ! isset(self::$inited[$key])) {
151
152 $params['args'] = $value;
153 $params['sections'] = self::$args['sections'][$key];
154 self::$inited[$key] = true;
155
156 DarkifyNavMenuOptions::instance($key, $params);
157 }
158 }
159 }
160
161 // Setup profile option framework
162 $params = array();
163 if (class_exists('DarkifyProfileOptions') && ! empty(self::$args['profile_options'])) {
164 foreach (self::$args['profile_options'] as $key => $value) {
165 if (! empty(self::$args['sections'][$key]) && ! isset(self::$inited[$key])) {
166
167 $params['args'] = $value;
168 $params['sections'] = self::$args['sections'][$key];
169 self::$inited[$key] = true;
170
171 DarkifyProfileOptions::instance($key, $params);
172 }
173 }
174 }
175
176 // Setup taxonomy option framework
177 $params = array();
178 if (class_exists('DarkifyTaxonomyOptions') && ! empty(self::$args['taxonomy_options'])) {
179 $taxonomy = (isset($_GET['taxonomy'])) ? sanitize_text_field(wp_unslash($_GET['taxonomy'])) : '';
180 foreach (self::$args['taxonomy_options'] as $key => $value) {
181 if (! empty(self::$args['sections'][$key]) && ! isset(self::$inited[$key])) {
182
183 $params['args'] = $value;
184 $params['sections'] = self::$args['sections'][$key];
185 self::$inited[$key] = true;
186
187 DarkifyTaxonomyOptions::instance($key, $params);
188 }
189 }
190 }
191
192 // Setup widget option framework
193 if (class_exists('DarkifyWidget') && class_exists('WP_Widget_Factory') && ! empty(self::$args['widget_options'])) {
194 $wp_widget_factory = new WP_Widget_Factory();
195 global $wp_widget_factory;
196 foreach (self::$args['widget_options'] as $key => $value) {
197 if (! isset(self::$inited[$key])) {
198
199 self::$inited[$key] = true;
200 $wp_widget_factory->register(DarkifyWidget::instance($key, $value));
201 }
202 }
203 }
204
205 // Setup comment option framework
206 $params = array();
207 if (class_exists('DarkifyCommentMetabox') && ! empty(self::$args['comment_options'])) {
208 foreach (self::$args['comment_options'] as $key => $value) {
209 if (! empty(self::$args['sections'][$key]) && ! isset(self::$inited[$key])) {
210
211 $params['args'] = $value;
212 $params['sections'] = self::$args['sections'][$key];
213 self::$inited[$key] = true;
214
215 DarkifyCommentMetabox::instance($key, $params);
216 }
217 }
218 }
219
220 // Setup shortcode option framework
221 $params = array();
222 if (class_exists('DarkifyShortcoder') && ! empty(self::$args['shortcode_options'])) {
223 foreach (self::$args['shortcode_options'] as $key => $value) {
224 if (! empty(self::$args['sections'][$key]) && ! isset(self::$inited[$key])) {
225
226 $params['args'] = $value;
227 $params['sections'] = self::$args['sections'][$key];
228 self::$inited[$key] = true;
229
230 DarkifyShortcoder::instance($key, $params);
231 }
232 }
233
234 // Once editor setup for gutenberg and media buttons
235 if (class_exists('DarkifyShortcoder') && ! empty(self::$shortcode_instances)) {
236 foreach (self::$shortcode_instances as $instance) {
237 if (! empty($instance['show_in_editor'])) {
238 DarkifyShortcoder::once_editor_setup();
239 break;
240 }
241 }
242 }
243 }
244
245 do_action('darkify_loaded');
246 }
247
248 // Create options
249 public static function createOptions($id, $args = array())
250 {
251 self::$args['admin_options'][$id] = $args;
252 }
253
254 // Create customize options
255 public static function createCustomizeOptions($id, $args = array())
256 {
257 self::$args['customize_options'][$id] = $args;
258 }
259
260 // Create metabox options
261 public static function createMetabox($id, $args = array())
262 {
263 self::$args['metabox_options'][$id] = $args;
264 }
265
266 // Create menu options
267 public static function createNavMenuOptions($id, $args = array())
268 {
269 self::$args['nav_menu_options'][$id] = $args;
270 }
271
272 // Create shortcoder options
273 public static function createShortcoder($id, $args = array())
274 {
275 self::$args['shortcode_options'][$id] = $args;
276 }
277
278 // Create taxonomy options
279 public static function createTaxonomyOptions($id, $args = array())
280 {
281 self::$args['taxonomy_options'][$id] = $args;
282 }
283
284 // Create profile options
285 public static function createProfileOptions($id, $args = array())
286 {
287 self::$args['profile_options'][$id] = $args;
288 }
289
290 // Create widget
291 public static function createWidget($id, $args = array())
292 {
293 self::$args['widget_options'][$id] = $args;
294 self::set_used_fields($args);
295 }
296
297 // Create comment metabox
298 public static function createCommentMetabox($id, $args = array())
299 {
300 self::$args['comment_options'][$id] = $args;
301 }
302
303 // Create section
304 public static function createSection($id, $sections)
305 {
306 self::$args['sections'][$id][] = $sections;
307 self::set_used_fields($sections);
308 }
309
310 // Set directory constants
311 public static function constants()
312 {
313
314 // We need this path-finder code for set URL of framework
315 $dirname = str_replace('//', '/', wp_normalize_path(dirname(dirname(self::$file))));
316 $theme_dir = str_replace('//', '/', wp_normalize_path(get_parent_theme_file_path()));
317 $plugin_dir = str_replace('//', '/', wp_normalize_path(WP_PLUGIN_DIR));
318 $plugin_dir = str_replace('/opt/bitnami', '/bitnami', $plugin_dir);
319 $located_plugin = (preg_match('#' . self::sanitize_dirname($plugin_dir) . '#', self::sanitize_dirname($dirname))) ? true : false;
320 $directory = ($located_plugin) ? $plugin_dir : $theme_dir;
321 $directory_uri = ($located_plugin) ? WP_PLUGIN_URL : get_parent_theme_file_uri();
322 $foldername = str_replace($directory, '', $dirname);
323 $protocol_uri = (is_ssl()) ? 'https' : 'http';
324 $directory_uri = set_url_scheme($directory_uri, $protocol_uri);
325
326 self::$dir = $dirname;
327 self::$url = $directory_uri . $foldername;
328 }
329
330 // Include file helper
331 public static function include_plugin_file($file, $load = true)
332 {
333
334 $path = '';
335 $file = ltrim($file, '/');
336 $override = apply_filters('darkify_override', 'darkify-override');
337
338 if (file_exists(get_parent_theme_file_path($override . '/' . $file))) {
339 $path = get_parent_theme_file_path($override . '/' . $file);
340 } elseif (file_exists(get_theme_file_path($override . '/' . $file))) {
341 $path = get_theme_file_path($override . '/' . $file);
342 } elseif (file_exists(self::$dir . '/' . $override . '/' . $file)) {
343 $path = self::$dir . '/' . $override . '/' . $file;
344 } elseif (file_exists(self::$dir . '/' . $file)) {
345 $path = self::$dir . '/' . $file;
346 }
347
348 if (! empty($path) && ! empty($file) && $load) {
349
350 global $wp_query;
351
352 if (is_object($wp_query) && function_exists('load_template')) {
353
354 load_template($path, true);
355 } else {
356
357 require_once($path);
358 }
359 } else {
360
361 return self::$dir . '/' . $file;
362 }
363 }
364
365 // Is active plugin helper
366 public static function is_active_plugin($file = '')
367 {
368 return in_array($file, (array) get_option('active_plugins', array()));
369 }
370
371 // Sanitize dirname
372 public static function sanitize_dirname($dirname)
373 {
374 return preg_replace('/[^A-Za-z]/', '', $dirname);
375 }
376
377 // Set url constant
378 public static function include_plugin_url($file)
379 {
380 return esc_url(self::$url) . '/' . ltrim($file, '/');
381 }
382
383 // Include files
384 public static function includes()
385 {
386
387 // Include common functions
388 self::include_plugin_file('functions/actions.php');
389 self::include_plugin_file('functions/helpers.php');
390 self::include_plugin_file('functions/sanitize.php');
391 self::include_plugin_file('functions/validate.php');
392
393 // Include free version Classes
394 self::include_plugin_file('Classes/abstract.class.php');
395 self::include_plugin_file('Classes/fields.class.php');
396 self::include_plugin_file('Classes/DarkifyOptions.php');
397 self::include_plugin_file('Classes/DarkifyMetabox.php');
398
399
400 // Include all framework fields
401 $fields = apply_filters('darkify_fields', array(
402 'accordion',
403 'background',
404 'backup',
405 'border',
406 'button_set',
407 'callback',
408 'checkbox',
409 'code_editor',
410 'color',
411 'color_group',
412 'content',
413 'date',
414 'datetime',
415 'dimensions',
416 'fieldset',
417 'gallery',
418 'group',
419 'heading',
420 'icon',
421 'image_select',
422 'layout_preset',
423 'link',
424 'link_color',
425 'map',
426 'media',
427 'notice',
428 'number',
429 'palette',
430 'radio',
431 'repeater',
432 'select',
433 'slider',
434 'sortable',
435 'sorter',
436 'spacing',
437 'spinner',
438 'subheading',
439 'submessage',
440 'switcher_shortcode',
441 'switcher',
442 'tabbed',
443 'ta_help',
444 'text',
445 'textarea',
446 'upload',
447 'wp_editor',
448 ));
449
450 if (! empty($fields)) {
451 foreach ($fields as $field) {
452 if (! class_exists('DarkifyField_' . $field) && class_exists('DarkifyFields')) {
453 self::include_plugin_file('fields/' . $field . '/' . $field . '.php');
454 }
455 }
456 }
457 }
458
459 // Set all of used fields
460 public static function set_used_fields($sections)
461 {
462
463 if (! empty($sections['fields'])) {
464
465 foreach ($sections['fields'] as $field) {
466
467 if (! empty($field['fields'])) {
468 self::set_used_fields($field);
469 }
470
471 if (! empty($field['tabs'])) {
472 self::set_used_fields(array('fields' => $field['tabs']));
473 }
474
475 if (! empty($field['accordions'])) {
476 self::set_used_fields(array('fields' => $field['accordions']));
477 }
478
479 if (! empty($field['elements'])) {
480 self::set_used_fields(array('fields' => $field['elements']));
481 }
482
483 if (! empty($field['type'])) {
484 self::$fields[$field['type']] = $field;
485 }
486 }
487 }
488 }
489
490 // Enqueue admin and fields styles and scripts
491 public static function add_admin_enqueue_scripts()
492 {
493
494 if (! self::$enqueue) {
495
496 // Loads scripts and styles only when needed
497 $wpscreen = get_current_screen();
498
499 if (! empty(self::$args['admin_options'])) {
500 foreach (self::$args['admin_options'] as $argument) {
501 if (substr($wpscreen->id, -strlen($argument['menu_slug'])) === $argument['menu_slug']) {
502 self::$enqueue = true;
503 }
504 }
505 }
506
507 if (! empty(self::$args['metabox_options'])) {
508 foreach (self::$args['metabox_options'] as $argument) {
509 if (in_array($wpscreen->post_type, (array) $argument['post_type'])) {
510 self::$enqueue = true;
511 }
512 }
513 }
514
515 if (! empty(self::$args['taxonomy_options'])) {
516 foreach (self::$args['taxonomy_options'] as $argument) {
517 if (in_array($wpscreen->taxonomy, (array) $argument['taxonomy'])) {
518 self::$enqueue = true;
519 }
520 }
521 }
522
523 if (! empty(self::$shortcode_instances)) {
524 foreach (self::$shortcode_instances as $argument) {
525 if (($argument['show_in_editor'] && $wpscreen->base === 'post') || $argument['show_in_custom']) {
526 self::$enqueue = true;
527 }
528 }
529 }
530
531 if (! empty(self::$args['widget_options']) && ($wpscreen->id === 'widgets' || $wpscreen->id === 'customize')) {
532 self::$enqueue = true;
533 }
534
535 if (! empty(self::$args['customize_options']) && $wpscreen->id === 'customize') {
536 self::$enqueue = true;
537 }
538
539 if (! empty(self::$args['nav_menu_options']) && $wpscreen->id === 'nav-menus') {
540 self::$enqueue = true;
541 }
542
543 if (! empty(self::$args['profile_options']) && ($wpscreen->id === 'profile' || $wpscreen->id === 'user-edit')) {
544 self::$enqueue = true;
545 }
546
547 if (! empty(self::$args['comment_options']) && $wpscreen->id === 'comment') {
548 self::$enqueue = true;
549 }
550
551 if ($wpscreen->id === 'tools_page_darkify-welcome') {
552 self::$enqueue = true;
553 }
554 }
555
556 if (! apply_filters('darkify_enqueue_assets', self::$enqueue)) {
557 return;
558 }
559
560 // Admin utilities
561 wp_enqueue_media();
562
563 // Wp color picker
564 wp_enqueue_style('wp-color-picker');
565 wp_enqueue_script('wp-color-picker');
566
567 // Check for developer mode
568 $min = (self::$premium && SCRIPT_DEBUG) ? '' : '.min';
569
570 // Main style
571 wp_enqueue_style('darkify', self::include_plugin_url('assets/css/style' . $min . '.css'), array(), self::$version, 'all');
572
573 // Main RTL styles
574 if (is_rtl()) {
575 wp_enqueue_style('darkify-rtl', self::include_plugin_url('assets/css/style-rtl' . $min . '.css'), array(), self::$version, 'all');
576 }
577
578 // Custom style
579 wp_enqueue_style('taf-custom', self::include_plugin_url('assets/css/taf-custom' . $min . '.css'), array(), self::$version, 'all');
580
581 // Custom Styles
582 wp_enqueue_style('darkify-help-page', self::include_plugin_url('assets/css/help-page' . $min . '.css'), array(), self::$version, 'all');
583
584 // Main scripts
585 wp_enqueue_script('darkify-plugins', self::include_plugin_url('assets/js/plugins' . $min . '.js'), array(), self::$version, true);
586 wp_enqueue_script('darkify', self::include_plugin_url('assets/js/main' . $min . '.js'), array('darkify-plugins'), self::$version, true);
587 wp_enqueue_script('darkify-help-page', self::include_plugin_url('assets/js/help-page' . $min . '.js'), array('darkify-plugins'), self::$version, true);
588
589 // Main variables
590 wp_localize_script('darkify', 'darkify_vars', array(
591 'color_palette' => apply_filters('darkify_color_palette', array()),
592 'i18n' => array(
593 'confirm' => esc_html__('Are you sure?', 'darkify'),
594 'typing_text' => esc_html__('Please enter %s or more characters', 'darkify'),
595 'searching_text' => esc_html__('Searching...', 'darkify'),
596 'no_results_text' => esc_html__('No results found.', 'darkify'),
597 ),
598 'ajaxurl' => admin_url('admin-ajax.php'),
599 'nonce' => wp_create_nonce('save_options'),
600 ));
601
602 // Enqueue fields scripts and styles
603 $enqueued = array();
604
605 if (! empty(self::$fields)) {
606 foreach (self::$fields as $field) {
607 if (! empty($field['type'])) {
608 $classname = 'DarkifyField_' . $field['type'];
609 if (class_exists($classname) && method_exists($classname, 'enqueue')) {
610 $instance = new $classname($field);
611 if (method_exists($classname, 'enqueue')) {
612 $instance->enqueue();
613 }
614 unset($instance);
615 }
616 }
617 }
618 }
619
620 do_action('darkify_enqueue');
621 }
622
623 // Add typography enqueue styles to front page
624 public static function add_typography_enqueue_styles()
625 {
626
627 if (! empty(self::$webfonts)) {
628
629 if (! empty(self::$webfonts['enqueue'])) {
630
631 $query = array();
632 $fonts = array();
633
634 foreach (self::$webfonts['enqueue'] as $family => $styles) {
635 $fonts[] = $family . ((! empty($styles)) ? ':' . implode(',', $styles) : '');
636 }
637
638 if (! empty($fonts)) {
639 $query['family'] = implode('%7C', $fonts);
640 }
641
642 if (! empty(self::$subsets)) {
643 $query['subset'] = implode(',', self::$subsets);
644 }
645
646 $query['display'] = 'swap';
647
648 wp_enqueue_style('darkify-google-web-fonts', esc_url(add_query_arg($query, '//fonts.googleapis.com/css')), array(), null);
649 }
650
651 if (! empty(self::$webfonts['async'])) {
652
653 $fonts = array();
654
655 foreach (self::$webfonts['async'] as $family => $styles) {
656 $fonts[] = $family . ((! empty($styles)) ? ':' . implode(',', $styles) : '');
657 }
658 wp_enqueue_script('darkify-google-web-fonts', self::include_plugin_url('assets/js/webfont.js'), array(), self::$version, true);
659 wp_localize_script('darkify-google-web-fonts', 'WebFontConfig', array('google' => array('families' => $fonts)));
660 }
661 }
662 }
663
664 // Add admin body class
665 public static function add_admin_body_class($classes)
666 {
667
668 if (apply_filters('darkify_fa4', false)) {
669 $classes .= 'darkify-fa5-shims';
670 }
671
672 return $classes;
673 }
674
675 // Add custom css to front page
676 public static function add_custom_css()
677 {
678
679 if (! empty(self::$css)) {
680 echo '<style type="text/css">' . esc_html(wp_strip_all_tags(self::$css)) . '</style>';
681 }
682 }
683
684 // Add a new framework field
685 public static function field($field = array(), $value = '', $unique = '', $where = '', $parent = '')
686 {
687
688 // Check for unallow fields
689 if (! empty($field['_notice'])) {
690
691 $field_type = $field['type'];
692
693 $field = array();
694 $field['content'] = esc_html__('Oops! Not allowed.', 'darkify') . ' <strong>(' . $field_type . ')</strong>';
695 $field['type'] = 'notice';
696 $field['style'] = 'danger';
697 }
698
699 $depend = '';
700 $visible = '';
701 $unique = (! empty($unique)) ? $unique : '';
702 $class = (! empty($field['class'])) ? ' ' . esc_attr($field['class']) : '';
703 $is_pseudo = (! empty($field['pseudo'])) ? ' darkify-pseudo-field' : '';
704 $field_type = (! empty($field['type'])) ? esc_attr($field['type']) : '';
705
706 if (! empty($field['dependency'])) {
707
708 $dependency = $field['dependency'];
709 $depend_visible = '';
710 $data_controller = '';
711 $data_condition = '';
712 $data_value = '';
713 $data_global = '';
714
715 if (is_array($dependency[0])) {
716 $data_controller = implode('|', array_column($dependency, 0));
717 $data_condition = implode('|', array_column($dependency, 1));
718 $data_value = implode('|', array_column($dependency, 2));
719 $data_global = implode('|', array_column($dependency, 3));
720 $depend_visible = implode('|', array_column($dependency, 4));
721 } else {
722 $data_controller = (! empty($dependency[0])) ? $dependency[0] : '';
723 $data_condition = (! empty($dependency[1])) ? $dependency[1] : '';
724 $data_value = (! empty($dependency[2])) ? $dependency[2] : '';
725 $data_global = (! empty($dependency[3])) ? $dependency[3] : '';
726 $depend_visible = (! empty($dependency[4])) ? $dependency[4] : '';
727 }
728
729 $depend .= ' data-controller="' . esc_attr($data_controller) . '"';
730 $depend .= ' data-condition="' . esc_attr($data_condition) . '"';
731 $depend .= ' data-value="' . esc_attr($data_value) . '"';
732 $depend .= (! empty($data_global)) ? ' data-depend-global="true"' : '';
733
734 $visible = (! empty($depend_visible)) ? ' darkify-depend-visible' : ' darkify-depend-hidden';
735 }
736
737 // These attributes has been sanitized above.
738 echo '<div class="darkify-field darkify-field-' . esc_attr($field_type) . esc_attr($is_pseudo) . esc_attr($class) . esc_attr($visible) . '"' . wp_kses_post($depend) . '>';
739
740 if (! empty($field_type)) {
741
742 if (! empty($field['title'])) {
743 echo '<div class="darkify-title">';
744 echo '<h4>' . esc_html($field['title']) . '</h4>';
745 echo (! empty($field['subtitle'])) ? '<div class="darkify-subtitle-text">' . wp_kses_post($field['subtitle']) . '</div>' : '';
746 echo '</div>';
747 }
748
749 echo (! empty($field['title'])) ? '<div class="darkify-fieldset">' : '';
750
751 $value = (! isset($value) && isset($field['default'])) ? $field['default'] : $value;
752 $value = (isset($field['value'])) ? $field['value'] : $value;
753
754 $classname = 'DarkifyField_' . $field_type;
755
756 if (class_exists($classname)) {
757 $instance = new $classname($field, $value, $unique, $where, $parent);
758 $instance->render();
759 } else {
760 echo '<p>' . esc_html__('Field not found!', 'darkify') . '</p>';
761 }
762 } else {
763 echo '<p>' . esc_html__('Field not found!', 'darkify') . '</p>';
764 }
765
766 echo (! empty($field['title'])) ? '</div>' : '';
767 echo '<div class="clear"></div>';
768 echo '</div>';
769 }
770 }
771 }
772
773 Darkify::init(__FILE__, true);
774