PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.3.3
StreamCast – bring live radio to your site with a sleek player v2.3.3
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.3.3, at admin/codestar-framework/classes/setup.class.php

808 lines 27.0 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.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( '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['elements'] ) ) {
489 self::set_used_fields( array( 'fields' => $field['elements'] ) );
490 }
491
492 if ( ! empty( $field['type'] ) ) {
493 self::$fields[$field['type']] = $field;
494 }
495
496 }
497
498 }
499
500 }
501
502 // Enqueue admin and fields styles and scripts
503 public static function add_admin_enqueue_scripts() {
504
505 if ( ! self::$enqueue ) {
506
507 // Loads scripts and styles only when needed
508 $wpscreen = get_current_screen();
509
510 if ( ! empty( self::$args['admin_options'] ) ) {
511 foreach ( self::$args['admin_options'] as $argument ) {
512 if ( substr( $wpscreen->id, -strlen( $argument['menu_slug'] ) ) === $argument['menu_slug'] ) {
513 self::$enqueue = true;
514 }
515 }
516 }
517
518 if ( ! empty( self::$args['metabox_options'] ) ) {
519 foreach ( self::$args['metabox_options'] as $argument ) {
520 if ( in_array( $wpscreen->post_type, (array) $argument['post_type'] ) ) {
521 self::$enqueue = true;
522 }
523 }
524 }
525
526 if ( ! empty( self::$args['taxonomy_options'] ) ) {
527 foreach ( self::$args['taxonomy_options'] as $argument ) {
528 if ( in_array( $wpscreen->taxonomy, (array) $argument['taxonomy'] ) ) {
529 self::$enqueue = true;
530 }
531 }
532 }
533
534 if ( ! empty( self::$shortcode_instances ) ) {
535 foreach ( self::$shortcode_instances as $argument ) {
536 if ( ( $argument['show_in_editor'] && $wpscreen->base === 'post' ) || $argument['show_in_custom'] ) {
537 self::$enqueue = true;
538 }
539 }
540 }
541
542 if ( ! empty( self::$args['widget_options'] ) && ( $wpscreen->id === 'widgets' || $wpscreen->id === 'customize' ) ) {
543 self::$enqueue = true;
544 }
545
546 if ( ! empty( self::$args['customize_options'] ) && $wpscreen->id === 'customize' ) {
547 self::$enqueue = true;
548 }
549
550 if ( ! empty( self::$args['nav_menu_options'] ) && $wpscreen->id === 'nav-menus' ) {
551 self::$enqueue = true;
552 }
553
554 if ( ! empty( self::$args['profile_options'] ) && ( $wpscreen->id === 'profile' || $wpscreen->id === 'user-edit' ) ) {
555 self::$enqueue = true;
556 }
557
558 if ( ! empty( self::$args['comment_options'] ) && $wpscreen->id === 'comment' ) {
559 self::$enqueue = true;
560 }
561
562 if ( $wpscreen->id === 'tools_page_csf-welcome' ) {
563 self::$enqueue = true;
564 }
565
566 }
567
568 if ( ! apply_filters( 'csf_enqueue_assets', self::$enqueue ) ) {
569 return;
570 }
571
572 // Admin utilities
573 wp_enqueue_media();
574
575 // Wp color picker
576 wp_enqueue_style( 'wp-color-picker' );
577 wp_enqueue_script( 'wp-color-picker' );
578
579 // Font awesome 4 and 5 loader
580 if ( apply_filters( 'csf_fa4', false ) ) {
581 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' );
582 } else {
583 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' );
584 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' );
585 }
586
587 // Check for developer mode
588 $min = ( self::$premium && SCRIPT_DEBUG ) ? '' : '.min';
589
590 // Main style
591 wp_enqueue_style( 'csf', self::include_plugin_url( 'assets/css/style'. $min .'.css' ), array(), self::$version, 'all' );
592
593 // Main RTL styles
594 if ( is_rtl() ) {
595 wp_enqueue_style( 'csf-rtl', self::include_plugin_url( 'assets/css/style-rtl'. $min .'.css' ), array(), self::$version, 'all' );
596 }
597
598 // Main scripts
599 wp_enqueue_script( 'csf-plugins', self::include_plugin_url( 'assets/js/plugins'. $min .'.js' ), array(), self::$version, true );
600 wp_enqueue_script( 'csf', self::include_plugin_url( 'assets/js/main'. $min .'.js' ), array( 'csf-plugins' ), self::$version, true );
601
602 // Main variables
603 wp_localize_script( 'csf', 'csf_vars', array(
604 'color_palette' => apply_filters( 'csf_color_palette', array() ),
605 'i18n' => array(
606 'confirm' => esc_html__( 'Are you sure?', 'csf' ),
607 'typing_text' => esc_html__( 'Please enter %s or more characters', 'csf' ),
608 'searching_text' => esc_html__( 'Searching...', 'csf' ),
609 'no_results_text' => esc_html__( 'No results found.', 'csf' ),
610 ),
611 ) );
612
613 // Enqueue fields scripts and styles
614 $enqueued = array();
615
616 if ( ! empty( self::$fields ) ) {
617 foreach ( self::$fields as $field ) {
618 if ( ! empty( $field['type'] ) ) {
619 $classname = 'CSF_Field_' . $field['type'];
620 if ( class_exists( $classname ) && method_exists( $classname, 'enqueue' ) ) {
621 $instance = new $classname( $field );
622 if ( method_exists( $classname, 'enqueue' ) ) {
623 $instance->enqueue();
624 }
625 unset( $instance );
626 }
627 }
628 }
629 }
630
631 do_action( 'csf_enqueue' );
632
633 }
634
635 // Add typography enqueue styles to front page
636 public static function add_typography_enqueue_styles() {
637
638 if ( ! empty( self::$webfonts ) ) {
639
640 if ( ! empty( self::$webfonts['enqueue'] ) ) {
641
642 $query = array();
643 $fonts = array();
644
645 foreach ( self::$webfonts['enqueue'] as $family => $styles ) {
646 $fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' );
647 }
648
649 if ( ! empty( $fonts ) ) {
650 $query['family'] = implode( '%7C', $fonts );
651 }
652
653 if ( ! empty( self::$subsets ) ) {
654 $query['subset'] = implode( ',', self::$subsets );
655 }
656
657 $query['display'] = 'swap';
658
659 wp_enqueue_style( 'csf-google-web-fonts', esc_url( add_query_arg( $query, '//fonts.googleapis.com/css' ) ), array(), null );
660
661 }
662
663 if ( ! empty( self::$webfonts['async'] ) ) {
664
665 $fonts = array();
666
667 foreach ( self::$webfonts['async'] as $family => $styles ) {
668 $fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' );
669 }
670
671 wp_enqueue_script( 'csf-google-web-fonts', esc_url( '//ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js' ), array(), null );
672
673 wp_localize_script( 'csf-google-web-fonts', 'WebFontConfig', array( 'google' => array( 'families' => $fonts ) ) );
674
675 }
676
677 }
678
679 }
680
681 // Add admin body class
682 public static function add_admin_body_class( $classes ) {
683
684 if ( apply_filters( 'csf_fa4', false ) ) {
685 $classes .= 'csf-fa5-shims';
686 }
687
688 return $classes;
689
690 }
691
692 // Add custom css to front page
693 public static function add_custom_css() {
694
695 if ( ! empty( self::$css ) ) {
696 echo '<style type="text/css">'. wp_strip_all_tags( self::$css ) .'</style>';
697 }
698
699 }
700
701 // Add a new framework field
702 public static function field( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) {
703
704 // Check for unallow fields
705 if ( ! empty( $field['_notice'] ) ) {
706
707 $field_type = $field['type'];
708
709 $field = array();
710 $field['content'] = esc_html__( 'Oops! Not allowed.', 'csf' ) .' <strong>('. $field_type .')</strong>';
711 $field['type'] = 'notice';
712 $field['style'] = 'danger';
713
714 }
715
716 $depend = '';
717 $visible = '';
718 $unique = ( ! empty( $unique ) ) ? $unique : '';
719 $class = ( ! empty( $field['class'] ) ) ? ' ' . esc_attr( $field['class'] ) : '';
720 $is_pseudo = ( ! empty( $field['pseudo'] ) ) ? ' csf-pseudo-field' : '';
721 $field_type = ( ! empty( $field['type'] ) ) ? esc_attr( $field['type'] ) : '';
722
723 if ( ! empty( $field['dependency'] ) ) {
724
725 $dependency = $field['dependency'];
726 $depend_visible = '';
727 $data_controller = '';
728 $data_condition = '';
729 $data_value = '';
730 $data_global = '';
731
732 if ( is_array( $dependency[0] ) ) {
733 $data_controller = implode( '|', array_column( $dependency, 0 ) );
734 $data_condition = implode( '|', array_column( $dependency, 1 ) );
735 $data_value = implode( '|', array_column( $dependency, 2 ) );
736 $data_global = implode( '|', array_column( $dependency, 3 ) );
737 $depend_visible = implode( '|', array_column( $dependency, 4 ) );
738 } else {
739 $data_controller = ( ! empty( $dependency[0] ) ) ? $dependency[0] : '';
740 $data_condition = ( ! empty( $dependency[1] ) ) ? $dependency[1] : '';
741 $data_value = ( ! empty( $dependency[2] ) ) ? $dependency[2] : '';
742 $data_global = ( ! empty( $dependency[3] ) ) ? $dependency[3] : '';
743 $depend_visible = ( ! empty( $dependency[4] ) ) ? $dependency[4] : '';
744 }
745
746 $depend .= ' data-controller="'. esc_attr( $data_controller ) .'"';
747 $depend .= ' data-condition="'. esc_attr( $data_condition ) .'"';
748 $depend .= ' data-value="'. esc_attr( $data_value ) .'"';
749 $depend .= ( ! empty( $data_global ) ) ? ' data-depend-global="true"' : '';
750
751 $visible = ( ! empty( $depend_visible ) ) ? ' csf-depend-visible' : ' csf-depend-hidden';
752
753 }
754
755 // These attributes has been sanitized above.
756 echo '<div class="csf-field csf-field-'. $field_type . $is_pseudo . $class . $visible .'"'. $depend .'>';
757
758 if ( ! empty( $field_type ) ) {
759
760 if ( ! empty( $field['title'] ) ) {
761 echo '<div class="csf-title">';
762 echo '<h4>'. $field['title'] .'</h4>';
763 echo ( ! empty( $field['subtitle'] ) ) ? '<div class="csf-subtitle-text">'. $field['subtitle'] .'</div>' : '';
764 echo '</div>';
765 }
766
767 echo ( ! empty( $field['title'] ) ) ? '<div class="csf-fieldset">' : '';
768
769 $value = ( ! isset( $value ) && isset( $field['default'] ) ) ? $field['default'] : $value;
770 $value = ( isset( $field['value'] ) ) ? $field['value'] : $value;
771
772 $classname = 'CSF_Field_'. $field_type;
773
774 if ( class_exists( $classname ) ) {
775 $instance = new $classname( $field, $value, $unique, $where, $parent );
776 $instance->render();
777 } else {
778 echo '<p>'. esc_html__( 'Field not found!', 'csf' ) .'</p>';
779 }
780
781 } else {
782 echo '<p>'. esc_html__( 'Field not found!', 'csf' ) .'</p>';
783 }
784
785 echo ( ! empty( $field['title'] ) ) ? '</div>' : '';
786 echo '<div class="clear"></div>';
787 echo '</div>';
788
789 }
790
791 }
792
793 }
794
795 CSF_Setup::init( __FILE__, true );
796
797 /**
798 *
799 * Extended Setup Class for Shortland
800 *
801 * @since 1.0.0
802 * @version 1.0.0
803 *
804 */
805 if ( ! class_exists( 'CSF' ) ) {
806 class CSF extends CSF_Setup{}
807 }
808