PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 2.0.0
Adminify – White Label, Admin Menu Editor, Login Customizer v2.0.0
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / lib / adminify-framework / classes / setup.class.php

setup.class.php in Adminify – White Label, Admin Menu Editor, Login Customizer 2.0.0, at lib/adminify-framework/classes/setup.class.php

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