PluginProbe
Easy Hotel – Powerful Hotel Booking / trunk
Easy Hotel – Powerful Hotel Booking vtrunk
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 trunk, at admin/includes/framework/classes/setup.class.php

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