PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.1.4
StreamCast – bring live radio to your site with a sleek player v2.1.4
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / admin / codestar-framework / classes / setup.class.php

setup.class.php in StreamCast – bring live radio to your site with a sleek player 2.1.4, at admin/codestar-framework/classes/setup.class.php

786 lines 25.8 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' ) ) {
11 class CSF {
12
13 // Default constants
14 public static $premium = true;
15 public static $version = '2.2.2';
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( 'csf_init' );
66
67 // Setup textdomain
68 self::textdomain();
69
70 add_action( 'after_setup_theme', array( 'CSF', 'setup' ) );
71 add_action( 'init', array( 'CSF', 'setup' ) );
72 add_action( 'switch_theme', array( 'CSF', 'setup' ) );
73 add_action( 'admin_enqueue_scripts', array( 'CSF', 'add_admin_enqueue_scripts' ) );
74 add_action( 'wp_enqueue_scripts', array( 'CSF', 'add_typography_enqueue_styles' ), 80 );
75 add_action( 'wp_head', array( 'CSF', 'add_custom_css' ), 80 );
76 add_filter( 'admin_body_class', array( 'CSF', '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( 'CSF_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 CSF_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( 'CSF_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 CSF_Customize_Options::instance( $key, $params );
120
121 }
122 }
123 }
124
125 // Setup metabox option framework
126 $params = array();
127 if ( class_exists( 'CSF_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 CSF_Metabox::instance( $key, $params );
136
137 }
138 }
139 }
140
141 // Setup nav menu option framework
142 $params = array();
143 if ( class_exists( 'CSF_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 CSF_Nav_Menu_Options::instance( $key, $params );
152
153 }
154 }
155 }
156
157 // Setup profile option framework
158 $params = array();
159 if ( class_exists( 'CSF_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 CSF_Profile_Options::instance( $key, $params );
168
169 }
170 }
171 }
172
173 // Setup taxonomy option framework
174 $params = array();
175 if ( class_exists( 'CSF_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 CSF_Taxonomy_Options::instance( $key, $params );
185
186 }
187 }
188 }
189
190 // Setup widget option framework
191 if ( class_exists( 'CSF_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( CSF_Widget::instance( $key, $value ) );
198
199 }
200 }
201 }
202
203 // Setup comment option framework
204 $params = array();
205 if ( class_exists( 'CSF_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 CSF_Comment_Metabox::instance( $key, $params );
214
215 }
216 }
217 }
218
219 // Setup shortcode option framework
220 $params = array();
221 if ( class_exists( 'CSF_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 CSF_Shortcoder::instance( $key, $params );
230
231 }
232 }
233
234 // Once editor setup for gutenberg and media buttons
235 if ( class_exists( 'CSF_Shortcoder' ) && ! empty( self::$shortcode_instances ) ) {
236 foreach ( self::$shortcode_instances as $instance ) {
237 if ( ! empty( $instance['show_in_editor'] ) ) {
238 CSF_Shortcoder::once_editor_setup();
239 break;
240 }
241 }
242 }
243
244 }
245
246 do_action( 'csf_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( 'csf_override', 'csf-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( 'csf_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( 'CSF_Field_'. $field ) && class_exists( 'CSF_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( 'csf', 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_csf-welcome' ) {
551 self::$enqueue = true;
552 }
553
554 if ( ! apply_filters( 'csf_enqueue_assets', self::$enqueue ) ) {
555 return;
556 }
557
558 // Check for developer mode
559 $min = ( self::$premium && SCRIPT_DEBUG ) ? '' : '.min';
560
561 // Admin utilities
562 wp_enqueue_media();
563
564 // Wp color picker
565 wp_enqueue_style( 'wp-color-picker' );
566 wp_enqueue_script( 'wp-color-picker' );
567
568 // Font awesome 4 and 5 loader
569 if ( apply_filters( 'csf_fa4', false ) ) {
570 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' );
571 } else {
572 wp_enqueue_style( 'csf-fa5', 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all'. $min .'.css', array(), '5.15.3', 'all' );
573 wp_enqueue_style( 'csf-fa5-v4-shims', 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/v4-shims'. $min .'.css', array(), '5.15.3', 'all' );
574 }
575
576 // Main style
577 wp_enqueue_style( 'csf', self::include_plugin_url( 'assets/css/style'. $min .'.css' ), array(), self::$version, 'all' );
578
579 // Main RTL styles
580 if ( is_rtl() ) {
581 wp_enqueue_style( 'csf-rtl', self::include_plugin_url( 'assets/css/style-rtl'. $min .'.css' ), array(), self::$version, 'all' );
582 }
583
584 // Main scripts
585 wp_enqueue_script( 'csf-plugins', self::include_plugin_url( 'assets/js/plugins'. $min .'.js' ), array(), self::$version, true );
586 wp_enqueue_script( 'csf', self::include_plugin_url( 'assets/js/main'. $min .'.js' ), array( 'csf-plugins' ), self::$version, true );
587
588 // Main variables
589 wp_localize_script( 'csf', 'csf_vars', array(
590 'color_palette' => apply_filters( 'csf_color_palette', array() ),
591 'i18n' => array(
592 'confirm' => esc_html__( 'Are you sure?', 'csf' ),
593 'typing_text' => esc_html__( 'Please enter %s or more characters', 'csf' ),
594 'searching_text' => esc_html__( 'Searching...', 'csf' ),
595 'no_results_text' => esc_html__( 'No results found.', 'csf' ),
596 ),
597 ) );
598
599 // Enqueue fields scripts and styles
600 $enqueued = array();
601
602 if ( ! empty( self::$fields ) ) {
603 foreach ( self::$fields as $field ) {
604 if ( ! empty( $field['type'] ) ) {
605 $classname = 'CSF_Field_' . $field['type'];
606 if ( class_exists( $classname ) && method_exists( $classname, 'enqueue' ) ) {
607 $instance = new $classname( $field );
608 if ( method_exists( $classname, 'enqueue' ) ) {
609 $instance->enqueue();
610 }
611 unset( $instance );
612 }
613 }
614 }
615 }
616
617 do_action( 'csf_enqueue' );
618
619 }
620
621 // Add typography enqueue styles to front page
622 public static function add_typography_enqueue_styles() {
623
624 if ( ! empty( self::$webfonts ) ) {
625
626 if ( ! empty( self::$webfonts['enqueue'] ) ) {
627
628 $query = array();
629 $fonts = array();
630
631 foreach ( self::$webfonts['enqueue'] as $family => $styles ) {
632 $fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' );
633 }
634
635 if ( ! empty( $fonts ) ) {
636 $query['family'] = implode( '%7C', $fonts );
637 }
638
639 if ( ! empty( self::$subsets ) ) {
640 $query['subset'] = implode( ',', self::$subsets );
641 }
642
643 $query['display'] = 'swap';
644
645 wp_enqueue_style( 'csf-google-web-fonts', esc_url( add_query_arg( $query, '//fonts.googleapis.com/css' ) ), array(), null );
646
647 }
648
649 if ( ! empty( self::$webfonts['async'] ) ) {
650
651 $fonts = array();
652
653 foreach ( self::$webfonts['async'] as $family => $styles ) {
654 $fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' );
655 }
656
657 wp_enqueue_script( 'csf-google-web-fonts', esc_url( '//ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js' ), array(), null );
658
659 wp_localize_script( 'csf-google-web-fonts', 'WebFontConfig', array( 'google' => array( 'families' => $fonts ) ) );
660
661 }
662
663 }
664
665 }
666
667 // Add admin body class
668 public static function add_admin_body_class( $classes ) {
669
670 if ( apply_filters( 'csf_fa4', false ) ) {
671 $classes .= 'csf-fa5-shims';
672 }
673
674 return $classes;
675
676 }
677
678 // Add custom css to front page
679 public static function add_custom_css() {
680
681 if ( ! empty( self::$css ) ) {
682 echo '<style type="text/css">'. wp_strip_all_tags( self::$css ) .'</style>';
683 }
684
685 }
686
687 // Add a new framework field
688 public static function field( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) {
689
690 // Check for unallow fields
691 if ( ! empty( $field['_notice'] ) ) {
692
693 $field_type = $field['type'];
694
695 $field = array();
696 $field['content'] = esc_html__( 'Oops! Not allowed.', 'csf' ) .' <strong>('. $field_type .')</strong>';
697 $field['type'] = 'notice';
698 $field['style'] = 'danger';
699
700 }
701
702 $depend = '';
703 $visible = '';
704 $unique = ( ! empty( $unique ) ) ? $unique : '';
705 $class = ( ! empty( $field['class'] ) ) ? ' ' . esc_attr( $field['class'] ) : '';
706 $is_pseudo = ( ! empty( $field['pseudo'] ) ) ? ' csf-pseudo-field' : '';
707 $field_type = ( ! empty( $field['type'] ) ) ? esc_attr( $field['type'] ) : '';
708
709 if ( ! empty( $field['dependency'] ) ) {
710
711 $dependency = $field['dependency'];
712 $depend_visible = '';
713 $data_controller = '';
714 $data_condition = '';
715 $data_value = '';
716 $data_global = '';
717
718 if ( is_array( $dependency[0] ) ) {
719 $data_controller = implode( '|', array_column( $dependency, 0 ) );
720 $data_condition = implode( '|', array_column( $dependency, 1 ) );
721 $data_value = implode( '|', array_column( $dependency, 2 ) );
722 $data_global = implode( '|', array_column( $dependency, 3 ) );
723 $depend_visible = implode( '|', array_column( $dependency, 4 ) );
724 } else {
725 $data_controller = ( ! empty( $dependency[0] ) ) ? $dependency[0] : '';
726 $data_condition = ( ! empty( $dependency[1] ) ) ? $dependency[1] : '';
727 $data_value = ( ! empty( $dependency[2] ) ) ? $dependency[2] : '';
728 $data_global = ( ! empty( $dependency[3] ) ) ? $dependency[3] : '';
729 $depend_visible = ( ! empty( $dependency[4] ) ) ? $dependency[4] : '';
730 }
731
732 $depend .= ' data-controller="'. esc_attr( $data_controller ) .'"';
733 $depend .= ' data-condition="'. esc_attr( $data_condition ) .'"';
734 $depend .= ' data-value="'. esc_attr( $data_value ) .'"';
735 $depend .= ( ! empty( $data_global ) ) ? ' data-depend-global="true"' : '';
736
737 $visible = ( ! empty( $depend_visible ) ) ? ' csf-depend-visible' : ' csf-depend-hidden';
738
739 }
740
741 if ( ! empty( $field_type ) ) {
742
743 // These attributes has been sanitized above.
744 echo '<div class="csf-field csf-field-'. $field_type . $is_pseudo . $class . $visible .'"'. $depend .'>';
745
746 if ( ! empty( $field['fancy_title'] ) ) {
747 echo '<div class="csf-fancy-title">' . $field['fancy_title'] .'</div>';
748 }
749
750 if ( ! empty( $field['title'] ) ) {
751 echo '<div class="csf-title">';
752 echo '<h4>'. $field['title'] .'</h4>';
753 echo ( ! empty( $field['subtitle'] ) ) ? '<div class="csf-subtitle-text">'. $field['subtitle'] .'</div>' : '';
754 echo '</div>';
755 }
756
757 echo ( ! empty( $field['title'] ) || ! empty( $field['fancy_title'] ) ) ? '<div class="csf-fieldset">' : '';
758
759 $value = ( ! isset( $value ) && isset( $field['default'] ) ) ? $field['default'] : $value;
760 $value = ( isset( $field['value'] ) ) ? $field['value'] : $value;
761
762 $classname = 'CSF_Field_'. $field_type;
763
764 if ( class_exists( $classname ) ) {
765 $instance = new $classname( $field, $value, $unique, $where, $parent );
766 $instance->render();
767 } else {
768 echo '<p>'. esc_html__( 'Field not found!', 'csf' ) .'</p>';
769 }
770
771 } else {
772 echo '<p>'. esc_html__( 'Field not found!', 'csf' ) .'</p>';
773 }
774
775 echo ( ! empty( $field['title'] ) || ! empty( $field['fancy_title'] ) ) ? '</div>' : '';
776 echo '<div class="clear"></div>';
777 echo '</div>';
778
779 }
780
781 }
782
783 }
784
785 CSF::init( __FILE__ );
786