PluginProbe
Easy Hotel – Powerful Hotel Booking / 2.0.4
Easy Hotel – Powerful Hotel Booking v2.0.4
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / admin / includes / framework / classes / setup.class.php

setup.class.php in Easy Hotel – Powerful Hotel Booking 2.0.4, at admin/includes/framework/classes/setup.class.php

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