PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.2.0
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.2.0
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 / admin / ta-framework / classes / setup.class.php

setup.class.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.2.0, at admin/ta-framework/classes/setup.class.php

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