PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / classes / setup.class.php

setup.class.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/classes/setup.class.php

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