-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwp-hotel-booking.php
706 lines (610 loc) · 23.2 KB
/
wp-hotel-booking.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
<?php
/**
* Plugin Name: WP Hotel Booking
* Plugin URI: http://thimpress.com/
* Description: Full of professional features for a booking room system
* Author: ThimPress
* Version: 2.1.9
* Author URI: http://thimpress.com
* Text Domain: wp-hotel-booking
* Domain Path: /languages/
* Requires PHP: 7.4
* @package wp-hotel-booking
*/
use WPHB\TemplateHooks\CheckRoomsTemplate;
use WPHB\TemplateHooks\ArchiveRoomTemplate;
defined( 'ABSPATH' ) || exit;
const WPHB_FILE = __FILE__;
const WPHB_PLUGIN_PATH = __DIR__;
$default_headers = array(
'Version' => 'Version',
'TextDomain' => 'Text Domain',
);
$plugin_info = get_file_data( __FILE__, $default_headers, 'plugin' );
define( 'WPHB_VERSION', $plugin_info['Version'] );
define( 'WPHB_PLUGIN_URL', plugins_url( '', WPHB_FILE ) );
define( 'WPHB_BLOG_ID', get_current_blog_id() );
define( 'WPHB_TEMPLATES', WPHB_PLUGIN_PATH . '/templates/' );
const TP_HB_EXTRA = __FILE__;
const WPHB_DEBUG = 1;
const WPHB_API_V2 = 1;
const WPHB_SHOW_FORM = 0;
const WPHB_ROOM_CT = 'hb_room';
/**
* Class WP_Hotel_Booking
*/
class WP_Hotel_Booking {
/**
* Hold the instance of main class
*
* @var object
*/
protected static $_instance = null;
/**
* Plugin path
*
* @var string
*/
protected $_plugin_path = null;
/**
* Plugin URL
*
* @var string
*/
protected $_plugin_url = null;
/**
* @var WPHB_Cart
*/
public $cart = null;
/**
* @var null
*/
public $user = null;
/**
* Construction
*/
private function __construct() {
$this->includes();
global $wpdb;
$wpdb->hotel_booking_order_items = $wpdb->prefix . 'hotel_booking_order_items';
//add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
add_action( 'wp_print_scripts', array( $this, 'global_js' ) );
add_action( 'template_redirect', 'hb_handle_purchase_request', 999 );
// add_action( 'admin_init', array( $this, 'create_tables' ) );
register_activation_hook( plugin_basename( __FILE__ ), array( $this, 'install' ) );
register_deactivation_hook( plugin_basename( __FILE__ ), array( $this, 'uninstall' ) );
// add_action( 'plugin_loaded', array( $this, 'install' ) );
add_action( 'init', array( $this, 'init' ), 20 );
// create new blog in multisite
add_action( 'wpmu_new_blog', array( $this, 'create_new_blog' ), 10, 6 );
// multisite delete table in multisite
add_filter( 'wpmu_drop_tables', array( $this, 'delete_blog_table' ) );
add_action( 'admin_init', array( $this, 'deactivate_plugins_old' ) );
}
public function init() {
// load text domain
$this->load_text_domain();
// cart
$this->cart = WPHB_Cart::instance();
// user
$this->user = hb_get_current_user();
}
// public function create_tables() {
// WPHB_Install::create_tables();
// WPHB_Install::create_pages();
// }
// install hook
public function install() {
WPHB_Install::install();
$this->_include( 'includes/class-wphb-roles.php' );
}
// uninstall hook
public function uninstall() {
WPHB_Install::uninstall();
}
// create new blog table
public function create_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
WPHB_Install::create_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta );
}
// delete table when delete blog, multisite
public function delete_blog_table( $tables ) {
return WPHB_Install::delete_tables( $tables );
}
/**
* Deactive plugin already merge to core wp-hotel-booking
*/
public function deactivate_plugins_old() {
$flag = version_compare( get_option( 'hotel_booking_version' ), WPHB_VERSION, '>=' );
if ( $flag ) {
$plugins = apply_filters(
'_hb_deactivate_plugins_old',
array(
'wp-hotel-booking-block-room/wp-hotel-booking-block.php',
'wp-hotel-booking-coupon/wp-hotel-booking-coupon.php',
'wp-hotel-booking-report/wp-hotel-booking-report.php',
'wp-hotel-booking-booking-room/wp-hotel-booking-room.php',
)
);
foreach ( $plugins as $plugin ) {
if ( in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
deactivate_plugins( $plugin );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
}
}
}
/**
* Include a file
*
* @param string
* @param bool
* @param array
*/
public function _include( $file, $root = true, $args = array(), $unique = true ) {
if ( $root ) {
$file = $this->plugin_path( $file );
}
if ( is_array( $args ) ) {
extract( $args );
}
if ( file_exists( $file ) ) {
if ( $unique ) {
require_once $file;
} else {
require $file;
}
}
}
/**
* Get the full path of a file
*
* @param string
*
* @return string
*/
public function locate( $file ) {
return $this->_plugin_path . '/' . $file;
}
/**
* Includes common files and libraries
*/
public function includes() {
include_once WPHB_PLUGIN_PATH . '/vendor/autoload.php';
$this->include_files_global();
if ( is_admin() ) {
$this->admin_includes();
}
if ( ! is_admin() ) {
$this->frontend_includes();
}
CheckRoomsTemplate::instance()->init();
ArchiveRoomTemplate::instance()->init();
}
public function include_files_global() {
$this->_include( 'includes/class-wphb-autoloader.php' );
$this->_include( 'includes/class-wphb-template-loader.php' );
$this->_include( 'includes/class-wphb-ajax.php' );
$this->_include( 'includes/class-wphb-install.php' );
$this->_include( 'includes/class-wphb-rest-response.php' );
$this->_include( 'includes/class-wphb-gdpr.php' );
$this->_include( 'includes/class-wphb-helpers.php' );
$this->_include( 'includes/class-wphb-post-types.php' );
$this->_include( 'includes/wphb-core-functions.php' );
$this->_include( 'includes/wphb-functions.php' );
$this->_include( 'includes/class-wphb-resizer.php' );
$this->_include( 'includes/class-wphb-settings.php' );
$this->_include( 'includes/class-wphb-comments.php' );
$this->_include( 'includes/wphb-template-hooks.php' );
$this->_include( 'includes/wphb-template-functions.php' );
$this->_include( 'includes/wphb-widget-functions.php' );
$this->_include( 'includes/admin/helpers/class-wphb-override-template.php' );
// booking
$this->_include( 'includes/booking/wphb-booking-functions.php' );
$this->_include( 'includes/booking/wphb-booking-hooks.php' );
$this->_include( 'includes/booking/class-wphb-booking.php' );
$this->_include( 'includes/booking/class-wphb-booking-block.php' );
$this->_include( 'includes/booking/class-wphb-booking-room-available.php' );
// users
$this->_include( 'includes/user/wphb-user-functions.php' );
$this->_include( 'includes/user/class-wphb-user.php' );
// $this->_include( 'includes/class-wphb-roles.php' );
// products
$this->_include( 'includes/products/class-wphb-abstract-product.php' );
$this->_include( 'includes/products/class-wphb-product-room.php' );
// end products
$this->_include( 'includes/room/wphb-room-functions.php' );
$this->_include( 'includes/room/class-wphb-room.php' );
$this->_include( 'includes/plugins/wp-hotel-booking-extra/wp-hotel-booking-extra.php' );
// // end addon
$this->_include( 'includes/class-wphb-sessions.php' );
// cart
$this->_include( 'includes/cart/wphb-cart-functions.php' );
$this->_include( 'includes/cart/class-wphb-cart.php' );
$this->_include( 'includes/gateways/class-wphb-payment-gateway-base.php' );
$this->_include( 'includes/wphb-webhooks.php' );
// rest api
$this->_include( 'includes/abstracts/class-wphb-abstract-rest-api.php' );
$this->_include( 'includes/abstracts/class-wphb-abstract-rest-controller.php' );
$this->_include( 'includes/rest-api/class-wphb-core-api.php' );
$this->_include( 'includes/rest-api/class-wphb-admin-core-api.php' );
// wphb booking single rooms
$this->_include( 'includes/room/class-wphb-booking-room.php' );
// coupon hooks
$this->_include( 'includes/coupons/class-wphb-coupon-hooks.php' );
// block template
$this->_include( 'includes/abstracts/class-wphb-asbtract-block-template.php' );
$this->_include( 'includes/class-wphb-block-template-config.php' );
//meta boxes
$this->_include( 'includes/class-wphb-meta-box.php' );
//template-hook
$this->_include( 'includes/template-hooks/class-wphb-search.php' );
// Load Widgets support Elementor
add_action(
'plugins_loaded',
function () {
// Check Elementor, Thim El Kit is active.
if ( class_exists( 'Thim_EL_Kit' ) && defined( 'ELEMENTOR_VERSION' ) ) {
$this->_include( '/includes/elementor/modules/class-init.php' );
}
}
);
}
public function frontend_includes() {
// shortcodes
$this->_include( 'includes/shortcodes/class-wphb-abstract-shortcodes.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-cart.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-account.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-checkout.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-thankyou.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-lastest-reviews.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-best-reviews.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-rooms.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-mini-cart.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-slider.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-filter.php' );
// end shortcodes
if ( ! class_exists( 'Aq_Resize' ) ) {
$this->_include( 'includes/aq_resizer.php' );
}
}
public function admin_includes() {
$this->_include( 'includes/admin/class-wphb-admin.php' );
}
// load payments addons
/*public function plugins_loaded() {
// load text domain
$this->load_text_domain();
}*/
/**
* Get the path of the plugin with sub path
*
* @param string $sub
*
* @return string
*/
public function plugin_path( $sub = '' ) {
if ( ! $this->_plugin_path ) {
$this->_plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
}
return $this->_plugin_path . '/' . $sub;
}
/**
* Get the url of the plugin with sub path
*
* @param string $sub
*
* @return string
*/
public function plugin_url( $sub = '' ) {
if ( ! $this->_plugin_url ) {
$this->_plugin_url = untrailingslashit( plugins_url( '/', __FILE__ ) );
}
return $this->_plugin_url . '/' . $sub;
}
/**
* Load language for the plugin
*/
public function load_text_domain() {
// prefix
$prefix = basename( dirname( plugin_basename( __FILE__ ) ) );
$locale = get_locale();
$dir = $this->plugin_path( 'languages' );
$mofile = false;
$global_file = WP_LANG_DIR . '/plugins/' . $prefix . '-' . $locale . '.mo';
$plugin_file = $dir . '/' . $prefix . '-' . $locale . '.mo';
if ( file_exists( $global_file ) ) {
$mofile = $global_file;
} elseif ( file_exists( $plugin_file ) ) {
$mofile = $plugin_file;
}
if ( $mofile ) {
// In themes/plugins/mu-plugins directory
load_textdomain( 'wp-hotel-booking', $mofile );
}
}
/**
* Enqueue assets for the plugin
*/
public function enqueue_assets() {
$v_rand = uniqid();
$version = WPHB_VERSION;
$min = '.min';
if ( WPHB_Settings::is_debug() ) {
$min = '';
$version = $v_rand;
}
$dependencies = array(
'jquery',
'jquery-ui-sortable',
'jquery-ui-datepicker',
'wp-util',
'wp-api-fetch',
);
// Register styles
wp_register_style( 'wphb-ui-slider', $this->plugin_url( 'assets/lib/slider/nouislider.min.css' ) );
wp_register_style( 'wp-hotel-booking-libaries-style', $this->plugin_url( 'assets/css/libraries.css' ) );
wp_register_style( 'wp-hotel-booking-review-gallery', $this->plugin_url( "assets/css/review-gallery{$min}.css" ), [], $version );
wp_register_style( 'wp-admin-hotel-booking', $this->plugin_url( "assets/css/admin/admin.tp-hotel-booking{$min}.css" ), [], $version );
wp_register_style( 'wp-admin-single-room-v2', $this->plugin_url( "assets/css/admin/admin-single-room{$min}.css" ) );
wp_register_style( 'wp-admin-review-image', $this->plugin_url( "assets/css/admin/review-image{$min}.css" ), [], $v_rand );
wp_register_style( 'wp-admin-hotel-booking-fullcalendar', $this->plugin_url( 'assets/css/fullcalendar.min.css' ) );
wp_register_style( 'wp-hotel-booking', $this->plugin_url( 'assets/css/hotel-booking.css' ), [], WPHB_VERSION );
wp_register_style( 'wp-hotel-booking-theme-default', $this->plugin_url( 'assets/css/theme-default.css' ), [], WPHB_VERSION );
wp_register_style( 'wp-admin-hotel-booking-calendar-v2', $this->plugin_url( 'assets/css/admin/main.min.css' ) );
wp_register_style( 'tingle-css', $this->plugin_url( 'assets/lib/tingle.css' ) );
wp_register_style( 'flatpickr-css', $this->plugin_url( 'assets/lib/flatpickr.min.css' ) );
wp_register_style( 'wphb-single-room-css', WPHB_PLUGIN_URL . '/assets/css/booking-single-room.css', [], $version );
// End Register styles
// Register scripts
// select2
wp_register_script( 'wp-admin-hotel-booking-select2', $this->plugin_url( 'assets/js/select2.min.js' ) );
// dropdown pages
wp_register_script( 'wphb-dropdown-pages', $this->plugin_url( 'assets/js/admin/dropdown-pages.js' ) );
// moment
wp_register_script( 'wp-hotel-booking-moment', $this->plugin_url( 'assets/js/moment.min.js' ) );
//nouiSlider
wp_register_script( 'wphb-ui-slider', $this->plugin_url( 'assets/lib/slider/nouislider.min.js' ) );
$dependencies = array_merge( $dependencies, array( 'backbone' ) );
if ( is_admin() ) {
$screen = get_current_screen();
if ( $screen->base === 'edit-tags' && ( $screen->taxonomy === 'hb_room_type' || $screen->taxonomy === 'hb_room_capacity' ) ) {
wp_register_script(
'wp-admin-hotel-booking',
$this->plugin_url( 'assets/js/admin/admin.room-taxonomies.js' ),
$dependencies,
false,
true
);
}
}
wp_register_script(
'wp-admin-hotel-booking',
$this->plugin_url( "assets/js/admin/admin.hotel-booking{$min}.js" ),
array_merge( $dependencies, array( 'wphb-dropdown-pages' ) ),
$v_rand
);
wp_register_script(
'wp-admin-room-filter',
$this->plugin_url( "assets/js/admin/room-filter{$min}.js" ),
array_merge( $dependencies, array() ),
$v_rand
);
wp_register_script( 'wp-admin-hotel-booking-fullcalendar', $this->plugin_url( 'assets/js/fullcalendar.min.js' ), $dependencies );
wp_register_script(
'wp-hotel-booking',
$this->plugin_url( "assets/dist/js/frontend/hotel-booking{$min}.js" ),
$dependencies,
$version,
array(
'strategy' => 'defer',
)
);
wp_register_script(
'wp-hotel-booking-v2',
$this->plugin_url( "assets/dist/js/frontend/hotel-booking-v2{$min}.js" ),
$dependencies,
$version,
array(
'strategy' => 'defer',
)
);
wp_register_script(
'wp-hotel-booking-sort-by',
$this->plugin_url( "assets/dist/js/frontend/sort-by{$min}.js" ),
array(),
$version,
array(
'strategy' => 'defer',
)
);
wp_register_script(
'wp-hotel-booking-filter-by',
$this->plugin_url( "assets/dist/js/frontend/filter-by{$min}.js" ),
array(),
$version,
array(
'strategy' => 'defer',
)
);
wp_register_script(
'wp-hotel-booking-room-review',
$this->plugin_url( "assets/dist/js/frontend/room-review{$min}.js" ),
array(),
$version,
array(
'strategy' => 'defer',
)
);
wp_localize_script( 'wp-hotel-booking', 'hotel_booking_i18n', hb_i18n() );
// rooms slider widget
wp_register_script( 'wp-hotel-booking-gallery', $this->plugin_url( 'includes/libraries/camera/js/gallery.min.js' ), $dependencies ); // old camera
wp_register_script( 'flexslider', $this->plugin_url( 'includes/libraries/flexslider/jquery.flexslider.min.js' ), $dependencies, WPHB_VERSION ); // new flexslider
// owl carousel
wp_register_script( 'wp-hotel-booking-owl-carousel', $this->plugin_url( 'includes/libraries/owl-carousel/owl.carousel.min.js' ), $dependencies );
// calendar v2 : move addon to single rooms
wp_register_script( 'wp-admin-hotel-booking-calendar-v2', $this->plugin_url( 'assets/js/admin/main.min.js' ), $dependencies );
wp_register_script( 'wp-admin-hotel-booking-v2', $this->plugin_url( 'assets/js/admin/admin.hotel-booking-v2.js' ), $dependencies, WPHB_VERSION );
// Single room script.
wp_register_script(
'wpdb-single-room-js',
WPHB_PLUGIN_URL . "/assets/dist/js/frontend/wphb-single-room{$min}.js",
[],
$version,
[ 'strategy' => 'defer' ]
);
// End Register scripts
if ( is_admin() ) {
wp_enqueue_style( 'wp-admin-hotel-booking' );
wp_localize_script( 'wp-admin-hotel-booking', 'hotel_booking_i18n', hb_admin_i18n() );
wp_enqueue_script( 'wp-admin-hotel-booking' );
wp_enqueue_script( 'wp-admin-room-filter' );
wp_enqueue_script( 'backbone' );
wp_enqueue_style( 'wp-admin-single-room-v2' );
wp_enqueue_style( 'wp-admin-review-image' );
// report
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
/* fullcalendar */
wp_enqueue_script( 'wp-hotel-booking-moment' );
wp_enqueue_style( 'wp-admin-hotel-booking-fullcalendar' );
wp_enqueue_script( 'wp-admin-hotel-booking-fullcalendar' );
} else {
wp_enqueue_style( 'wphb-ui-slider' );
wp_enqueue_style( 'wp-hotel-booking' );
wp_enqueue_style( 'wp-hotel-booking-theme-default' );
wp_enqueue_style( 'wp-hotel-booking-review-gallery' );
wp_enqueue_script( 'wp-hotel-booking' );
wp_enqueue_script( 'wp-hotel-booking-v2' );
wp_enqueue_script( 'wp-hotel-booking-sort-by' );
wp_enqueue_script( 'wp-hotel-booking-filter-by' );
wp_enqueue_script( 'wp-hotel-booking-room-review' );
wp_enqueue_style( 'flatpickr-css' );
// Load scripts and styles for single room
if ( is_singular( 'hb_room' ) ) {
wp_enqueue_style( 'tingle-css' );
wp_enqueue_style( 'wphb-single-room-css' );
wp_enqueue_script( 'wpdb-single-room-js' );
wp_enqueue_script( 'wp-hotel-booking-gallery' );
wp_enqueue_script( 'flexslider' );
global $post;
$max_images = hb_settings()->get( 'max_review_image_number' );
if ( empty( $max_images ) ) {
$max_images = 10;
}
$max_file_size = hb_settings()->get( 'max_review_image_file_size' );
if ( empty( $max_file_size ) ) {
$max_file_size = 1000000;
}
$is_enable = intval( hb_settings()->get( 'enable_advanced_review' ) ) === 1;
wp_localize_script(
'wp-hotel-booking-room-review',
'HB_ROOM_REVIEW_GALLERY',
array(
'room_id' => $post->ID,
'is_enable' => $is_enable,
'max_images' => $max_images,
'max_file_size' => $max_file_size,
'max_image_error' => sprintf( esc_html__( 'The image number is greater than %s', 'wp-hotel-booking' ), $max_images ),
'file_type_error' => esc_html__( 'The image file type is invalid', 'wp-hotel-booking' ),
'max_file_size_error' => sprintf( esc_html__( 'The maximum file size is %s KB', 'wp-hotel-booking' ), $max_file_size ),
$max_file_size,
)
);
}
// rooms slider widget
wp_enqueue_script( 'wp-hotel-booking-owl-carousel' );
// booking in single rooms
//wp_enqueue_style( 'wp-hotel-booking-magnific-popup-css' );
wp_enqueue_script( 'wphb-ui-slider' );
//wp_enqueue_script( 'wp-hotel-booking-magnific-popup-js' );
}
wp_enqueue_style( 'wp-hotel-booking-libaries-style' );
// select2
wp_enqueue_script( 'wp-admin-hotel-booking-select2' );
// wp_enqueue_script( 'colorpicker' );
/* calendar v2 */
wp_enqueue_script( 'wp-admin-hotel-booking-calendar-v2' );
wp_enqueue_style( 'wp-admin-hotel-booking-calendar-v2' );
wp_enqueue_script( 'wp-admin-hotel-booking-v2' );
}
/**
* Output global js settings
*/
public function global_js() {
if ( is_user_logged_in() && is_admin() ) {
$screen = get_current_screen();
}
$upload_dir = wp_upload_dir();
$upload_base_url = $upload_dir['baseurl'];
$min_booking_date = get_option( 'tp_hotel_booking_minimum_booking_day' ) ? get_option( 'tp_hotel_booking_minimum_booking_day' ) : 0;
$cart_page_url = ! empty( hb_settings()->get( 'cart_page_id' ) ) ? get_permalink( hb_settings()->get( 'cart_page_id' ) ) : '';
$checkout_page_url = ! empty( hb_settings()->get( 'checkout_page_id' ) ) ? get_permalink( hb_settings()->get( 'checkout_page_id' ) ) : '';
$currency = get_option( 'tp_hotel_booking_currency', 'USD' );
$currency_symbol = hb_get_currency_symbol( $currency );
$thousands_separator = get_option( 'tp_hotel_booking_price_thousands_separator' ) ? get_option( 'tp_hotel_booking_price_thousands_separator' ) : ',';
$decimals_separator = get_option( 'tp_hotel_booking_price_decimals_separator' ) ? get_option( 'tp_hotel_booking_price_decimals_separator' ) : '.';
$number_decimal = get_option( 'tp_hotel_booking_price_number_of_decimal' ) ? get_option( 'tp_hotel_booking_price_number_of_decimal' ) : '0';
?>
<script type="text/javascript">
var hotel_settings = {
cart_page_url: '<?php echo esc_url( $cart_page_url ); ?>',
checkout_page_url: '<?php echo esc_url( $checkout_page_url ); ?>',
site_url: '<?php echo esc_url( site_url() ); ?>',
ajax: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
settings: <?php echo WPHB_Settings::instance()->toJson( apply_filters( 'hb_settings_fields', array( 'review_rating_required' ) ) ); ?>,
upload_base_url: '<?php echo esc_js( $upload_base_url ); ?>',
meta_key: {
prefix: '_hb_'
},
date_format: '<?php echo get_option( 'date_format' ); ?>',
nonce: '<?php echo esc_html( wp_create_nonce( 'hb_booking_nonce_action' ) ); ?>',
timezone: '<?php echo esc_html( current_time( 'timestamp' ) ); ?>',
min_booking_date: <?php echo esc_html( $min_booking_date ); ?>,
wphb_rest_url: '<?php echo get_rest_url(); ?>',
is_page_search: <?php echo is_page( hb_get_page_id( 'search' ) ) ? 1 : 0; ?>,
url_page_search: '<?php echo get_permalink( hb_get_page_id( 'search' ) ); ?>',
room_id: <?php echo isset( $screen->id ) && $screen->id == 'hb_room' ? get_the_ID() : 0; ?>,
block_dates:
<?php
$room_id = get_the_ID();
$selected_block = array();
if ( $room_id ) {
$calendar_id = get_post_meta( $room_id, 'hb_blocked_id', true );
if ( $calendar_id ) {
$selected_block = get_post_meta( $calendar_id, 'hb_blocked_time' );
}
}
echo json_encode( $selected_block );
?>
,
currency: '<?php echo $currency; ?>',
currency_symbol: '<?php echo $currency_symbol; ?>',
currency_position: '<?php echo get_option( 'tp_hotel_booking_price_currency_position', 'left' ); ?>',
thousands_separator: '<?php echo $thousands_separator; ?>',
decimals_separator: '<?php echo $decimals_separator; ?>',
number_decimal: '<?php echo $number_decimal; ?>',
user_id: '<?php echo get_current_user_id(); ?>',
}
</script>
<?php
}
/**
* Create an instance of the plugin if it is not created
*
* @static
* @return object|WP_Hotel_Booking
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
}
WP_Hotel_Booking::instance();