| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. |
| 3 |
add_action('wp_enqueue_scripts', 'eshb_wp_enqueue_scripts', 999); |
| 4 |
function eshb_wp_enqueue_scripts (){ |
| 5 |
|
| 6 |
$css_version = filemtime( ESHB_PL_PATH . 'public/assets/css/public.css' ); |
| 7 |
|
| 8 |
wp_enqueue_style( 'dashicons' ); |
| 9 |
wp_enqueue_style( 'eshb-daterangepicker-style', ESHB_PL_URL . 'public/assets/css/date-range-picker.css', array(), $css_version ); |
| 10 |
wp_enqueue_style( 'eshb-style', ESHB_PL_URL . 'public/assets/css/public.css', array(), $css_version ); |
| 11 |
wp_enqueue_style( 'eshb-fontawesome-style', ESHB_PL_URL . 'public/assets/css/fontawesome.all.min.css', array(), '7.2.0', 'all' ); |
| 12 |
wp_enqueue_style( 'swiper', ESHB_PL_URL . 'public/assets/css/swiper-bundle.min.css', array(), $css_version, 'all' ); |
| 13 |
wp_enqueue_script( 'jquery' ); |
| 14 |
wp_enqueue_script( 'moment' ); |
| 15 |
wp_enqueue_script( 'eshb-date-range-picker-js', ESHB_PL_URL . 'public/assets/js/date-range-picker.js', array('jquery'),'3.1',true ); |
| 16 |
wp_enqueue_script( 'eshb-swiper', ESHB_PL_URL . 'public/assets/js/swiper-bundle.min.js', array(),'12.1.4',false ); |
| 17 |
wp_enqueue_script( 'eshb-public-script', ESHB_PL_URL . 'public/assets/js/public.js', array(),'1.0.0',true ); |
| 18 |
wp_enqueue_script( 'eshb-booking-script', ESHB_PL_URL . 'public/assets/js/booking.js', array(), ESHB_VERSION, true ); |
| 19 |
|
| 20 |
|
| 21 |
// Get WordPress current locale |
| 22 |
$locale = get_locale(); |
| 23 |
$eshb_settings = get_option('eshb_settings'); |
| 24 |
$apply_text_default = isset($eshb_settings['string_apply']) && !empty($eshb_settings['string_apply']) ? $eshb_settings['string_apply'] : ''; |
| 25 |
$cancel_text_default = isset($eshb_settings['string_cancel']) && !empty($eshb_settings['string_cancel']) ? $eshb_settings['string_cancel'] : ''; |
| 26 |
|
| 27 |
ESHB_Helper::eshb_set_accomodation_localize(); |
| 28 |
|
| 29 |
// Cart blocking notice config for JS injection |
| 30 |
$eshb_notice_msg = ! empty( $eshb_settings['cart-blocking-notice-msg'] ) |
| 31 |
? esc_html( $eshb_settings['cart-blocking-notice-msg'] ) |
| 32 |
: esc_html__( 'Your reservation is held for', 'easy-hotel' ); |
| 33 |
wp_localize_script( 'eshb-booking-script', 'eshb_cart_notice', [ |
| 34 |
'enabled' => ! empty( $eshb_settings['cart-blocking-switcher'] ) ? '1' : '0', |
| 35 |
'msg' => $eshb_notice_msg, |
| 36 |
] ); |
| 37 |
|
| 38 |
wp_localize_script('eshb-public-script', 'eshb_rest', [ |
| 39 |
'root' => esc_url(rest_url()), |
| 40 |
'nonce' => wp_create_nonce('wp_rest') |
| 41 |
]); |
| 42 |
|
| 43 |
// Prepare translations dynamically based on current locale |
| 44 |
$translations = [ |
| 45 |
'applyLabel' => !empty($apply_text_default) ? eshb_get_translated_string($apply_text_default) : __('Apply', 'easy-hotel'), |
| 46 |
'cancelLabel' => !empty($cancel_text_default) ? eshb_get_translated_string($cancel_text_default) : __('Cancel', 'easy-hotel'), |
| 47 |
'BookedTooltip' => __('Already Booked!', 'easy-hotel'), |
| 48 |
'holidayTooltip' => __('This is Holiday!', 'easy-hotel'), |
| 49 |
'fromLabel' => __('From', 'easy-hotel'), |
| 50 |
'toLabel' => __('To', 'easy-hotel'), |
| 51 |
'customRangeLabel' => __('Custom Range', 'easy-hotel'), |
| 52 |
'weekLabel' => __('W', 'easy-hotel'), |
| 53 |
'firstDay' => get_option('start_of_week'), // Get WordPress's start of the week setting |
| 54 |
'currentLocale' => $locale, // Pass current locale for debugging or further use |
| 55 |
]; |
| 56 |
|
| 57 |
// Pass translations to JavaScript |
| 58 |
wp_localize_script('eshb-date-range-picker-js', 'eshb_daterangepicker_i18n', $translations); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|