PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.1.0
Forumax – AI Powered Advanced Community Forum Plugin v1.1.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / admin / settings / codestar-framework / classes / setup.class.php

setup.class.php in Forumax – AI Powered Advanced Community Forum Plugin 1.1.0, at includes/admin/settings/codestar-framework/classes/setup.class.php

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