WPBC_JS_IN_FOOTER ) ); wp_localize_script( 'wpbc-settings-calendar-page', 'wpbc_settings_calendar_page', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'wpbc_settings_calendar_ajax_nonce' ), 'action' => 'WPBC_AJX_SETTINGS_CALENDAR_SAVE', 'preview_action' => 'WPBC_AJX_SETTINGS_CALENDAR_PREVIEW', 'settings' => wpbc_settings_calendar__get_settings_response(), 'days_selection' => wpbc_settings_calendar__get_days_selection_response(), 'open_section' => wpbc_settings_calendar__get_open_section(), 'section_groups' => wpbc_settings_calendar__get_section_group_map(), 'section_menus' => wpbc_settings_calendar__get_section_menu_slug_map(), 'i18n' => array( 'saving' => __( 'Saving', 'booking' ), 'saved' => __( 'Calendar settings updated.', 'booking' ), 'save_failed' => __( 'Unable to save calendar settings.', 'booking' ), 'preview_failed' => __( 'Unable to refresh calendar preview.', 'booking' ), 'loading' => __( 'Loading', 'booking' ), 'premium_notice' => __( 'Advanced range rules are available in Booking Calendar Business Small or higher. Open the live demo to test the real behavior.', 'booking' ), 'premium_changeover_notice' => __( 'Changeover days are available in Booking Calendar Business Small or higher. Open the live demo to test the real behavior.', 'booking' ), 'premium_option_notice' => __( 'This option is available in Booking Calendar Business Small or higher.', 'booking' ), ), 'is_range_supported' => wpbc_settings_calendar__is_range_supported() ? 1 : 0, ) ); } add_action( 'wpbc_enqueue_js_files', 'wpbc_settings_calendar_enqueue_js_files', 66 ); /** * Print tooltip initializer for Calendar settings. * * @return void */ function wpbc_settings_calendar_print_tooltip_js() { if ( ! wpbc_settings_calendar__is_page() ) { return; } if ( function_exists( 'wpbc_bs_javascript_tooltips' ) ) { wpbc_bs_javascript_tooltips(); } } add_action( 'admin_footer', 'wpbc_settings_calendar_print_tooltip_js', 67 ); /** * Check whether current edition supports advanced range rules and change-over settings. * * @return bool */ function wpbc_settings_calendar__is_range_supported() { return class_exists( 'wpdev_bk_biz_s' ); } /** * Get the main Range days option title for the current edition. * * Free and Personal expose only the unrestricted two-click range. Business * Small and higher select one-click or two-click behavior in the subtype * controls shown below the main option. * * @return string */ function wpbc_settings_calendar__get_range_days_title() { return wpbc_settings_calendar__is_range_supported() ? __( 'Range days', 'booking' ) : __( 'Range days - 2 mouse clicks', 'booking' ); } /** * Calendar settings right-sidebar section navigation. * * @return array */ function wpbc_settings_calendar__get_section_navigation_items() { return array( 'days_selection' => array( 'menu_slug' => 'calendar_days_selection', 'group' => 'settings-calendar-days-selection', 'title' => __( 'Days Selection', 'booking' ), 'hint' => __( 'Choose how users can select days: single day, multiple days, or date range.', 'booking' ), 'font_icon' => 'wpbc-bi-calendar3-week', ), 'changeover_times' => array( 'menu_slug' => 'calendar_changeover_times', 'group' => 'settings-calendar-time', 'title' => __( 'Changeover and Times', 'booking' ), 'hint' => __( 'Configure changeover days, recurrent time, and changeover exceptions.', 'booking' ), 'font_icon' => 'wpbc_icn_flip', ), 'legend' => array( 'menu_slug' => 'calendar_legend', 'group' => 'settings-calendar-legend', 'title' => __( 'Calendar Legend', 'booking' ), 'hint' => __( 'Show or hide the calendar legend and configure each legend item.', 'booking' ), 'font_icon' => 'wpbc-bi-list-check', ), 'tooltips' => array( 'menu_slug' => 'calendar_tooltips', 'group' => 'settings-calendar-tooltips', 'title' => __( 'Calendar Dates Tooltips', 'booking' ), 'hint' => __( 'Configure mouse-over tooltips for booked times, availability, cost, and booking details.', 'booking' ), 'font_icon' => 'wpbc-bi-chat-square-dots', ), 'general' => array( 'menu_slug' => 'calendar_general', 'group' => 'settings-calendar-general', 'title' => __( 'Calendar General', 'booking' ), 'hint' => __( 'Configure month scrolling, week start day, and mobile month display.', 'booking' ), 'font_icon' => 'wpbc-bi-calendar2-range', ), ); } /** * Get section key to left-menu slug map for scripts. * * @return array */ function wpbc_settings_calendar__get_section_menu_slug_map() { $section_menus = array(); foreach ( wpbc_settings_calendar__get_section_navigation_items() as $section_key => $section ) { $section_menus[ $section_key ] = $section['menu_slug']; } return $section_menus; } /** * Get section key to collapsible group map for scripts. * * @return array */ function wpbc_settings_calendar__get_section_group_map() { $section_groups = array(); foreach ( wpbc_settings_calendar__get_section_navigation_items() as $section_key => $section ) { $section_groups[ $section_key ] = $section['group']; } return $section_groups; } /** * Get URL to the Calendar settings page with a right-sidebar section selected. * * @param string $section Section key. * @return string */ function wpbc_settings_calendar__get_section_url( $section ) { $sections = wpbc_settings_calendar__get_section_navigation_items(); $base_url = function_exists( 'wpbc_get_settings_calendar_url' ) ? wpbc_get_settings_calendar_url() : admin_url( 'admin.php?page=wpbc-settings&tab=calendar_settings' ); if ( empty( $sections[ $section ] ) ) { return $base_url; } return add_query_arg( array( 'wpbc_calendar_section' => $section, ), $base_url ); } /** * Get the Calendar settings section that should be opened on page load. * * @return string */ function wpbc_settings_calendar__get_open_section() { $sections = wpbc_settings_calendar__get_section_navigation_items(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $open_section = isset( $_REQUEST['wpbc_calendar_section'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpbc_calendar_section'] ) ) : ''; if ( isset( $sections[ $open_section ] ) ) { return $open_section; } return ''; } /** * Adjust the universal top path for Calendar section URLs. * * Calendar sections use wpbc_calendar_section instead of the reserved subtab * parameter, so we map the active section into the shared top path here. * * @param array $items Top path items. * @param WPBC_Page_Structure $page_structure_obj Page structure object. * @param array $top_path_config Top path config. * * @return array */ function wpbc_settings_calendar__top_path_items( $items, $page_structure_obj, $top_path_config ) { if ( ! is_object( $page_structure_obj ) || ! method_exists( $page_structure_obj, 'get_current_page_params' ) ) { return $items; } $current_page_params = $page_structure_obj->get_current_page_params(); if ( empty( $current_page_params['tab']['tag'] ) || 'calendar_settings' !== $current_page_params['tab']['tag'] ) { return $items; } $sections = wpbc_settings_calendar__get_section_navigation_items(); $section_key = wpbc_settings_calendar__get_open_section(); if ( empty( $section_key ) ) { $section_key = 'days_selection'; } if ( empty( $sections[ $section_key ]['title'] ) ) { return $items; } foreach ( $items as $item_index => $item ) { $items[ $item_index ]['active'] = false; } if ( ! empty( $items ) ) { $last_item_index = count( $items ) - 1; $section_titles = array_map( 'wp_strip_all_tags', wp_list_pluck( $sections, 'title' ) ); $last_title = isset( $items[ $last_item_index ]['title'] ) ? wp_strip_all_tags( $items[ $last_item_index ]['title'] ) : ''; if ( in_array( $last_title, $section_titles, true ) ) { array_pop( $items ); } } $items[] = array( 'title' => $sections[ $section_key ]['title'], 'url' => wpbc_settings_calendar__get_section_url( $section_key ), 'onclick' => '', 'active' => true, ); return $items; } add_filter( 'wpbc_ui_settings_top_path_items', 'wpbc_settings_calendar__top_path_items', 10, 3 ); /** * Manage capability. * * @return string */ function wpbc_settings_calendar__get_manage_cap() { $min_user_role = get_bk_option( 'booking_user_role_settings' ); $capability = array( 'administrator' => 'activate_plugins', 'editor' => 'publish_pages', 'author' => 'publish_posts', 'contributor' => 'edit_posts', 'subscriber' => 'read', ); return isset( $capability[ $min_user_role ] ) ? $capability[ $min_user_role ] : 'manage_options'; } /** * Get booking resources for preview toolbar. * * @return array */ function wpbc_settings_calendar__get_resources() { if ( function_exists( 'wpbc_settings_themes__get_resources' ) ) { return wpbc_settings_themes__get_resources(); } return array( array( 'id' => 1, 'title' => __( 'Default booking resource', 'booking' ), ), ); } /** * Sanitize preview resource ID. * * @param int|string $resource_id Resource ID. * * @return int */ function wpbc_settings_calendar__sanitize_preview_resource_id( $resource_id ) { if ( function_exists( 'wpbc_settings_themes__sanitize_preview_resource_id' ) ) { return wpbc_settings_themes__sanitize_preview_resource_id( $resource_id ); } return max( 1, absint( $resource_id ) ); } /** * Sanitize preview months count. * * @param int|string $months_count Months count. * * @return int */ function wpbc_settings_calendar__sanitize_preview_months_count( $months_count ) { $months_count = absint( $months_count ); $allowed = array( 1, 2, 3, 4, 6, 12 ); return in_array( $months_count, $allowed, true ) ? $months_count : 3; } /** * Get preview resource ID. * * @return int */ function wpbc_settings_calendar__get_preview_resource_id() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $resource_id = isset( $_GET['resource_id'] ) ? absint( wp_unslash( $_GET['resource_id'] ) ) : 1; return wpbc_settings_calendar__sanitize_preview_resource_id( $resource_id ); } /** * Get preview months count. * * @return int */ function wpbc_settings_calendar__get_preview_months_count() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $months_count = isset( $_GET['months_count'] ) ? absint( wp_unslash( $_GET['months_count'] ) ) : 2; return wpbc_settings_calendar__sanitize_preview_months_count( $months_count ); } /** * Get week day labels. * * @return array */ function wpbc_settings_calendar__get_weekday_options() { return array( '0' => __( 'Sunday', 'booking' ), '1' => __( 'Monday', 'booking' ), '2' => __( 'Tuesday', 'booking' ), '3' => __( 'Wednesday', 'booking' ), '4' => __( 'Thursday', 'booking' ), '5' => __( 'Friday', 'booking' ), '6' => __( 'Saturday', 'booking' ), ); } /** * Get maximum scroll options. * * @return array */ function wpbc_settings_calendar__get_max_month_options() { $options = array(); for ( $mm = 1; $mm < 12; $mm++ ) { $options[ $mm . 'm' ] = $mm . ' ' . __( 'month(s)', 'booking' ); } $options['18m'] = '18 ' . __( 'month(s)', 'booking' ); for ( $yy = 1; $yy < 11; $yy++ ) { $options[ $yy . 'y' ] = $yy . ' ' . __( 'year(s)', 'booking' ); } return $options; } /** * Get time options in 15 minute steps while preserving saved values. * * @param string $current Current time. * * @return array */ function wpbc_settings_calendar__get_time_options( $current = '' ) { $options = array(); for ( $hh = 0; $hh < 24; $hh++ ) { foreach ( array( 0, 15, 30, 45 ) as $mm ) { $time = sprintf( '%02d:%02d', $hh, $mm ); $options[ $time ] = function_exists( 'wpbc_time_localized' ) ? wpbc_time_localized( $time ) : $time; } } if ( '' !== $current && ! isset( $options[ $current ] ) && preg_match( '/^\d{2}:\d{2}$/', $current ) ) { $options[ $current ] = function_exists( 'wpbc_time_localized' ) ? wpbc_time_localized( $current ) : $current; ksort( $options ); } return $options; } /** * Get configurable legend item options. * * @return array */ function wpbc_settings_calendar__get_legend_items_config() { return array( 'available' => array( 'label' => __( 'Available item', 'booking' ), 'description' => sprintf( __( 'Activate and type your %1$stitle of available%2$s item in legend', 'booking' ), '', '' ), 'placeholder' => __( 'Available', 'booking' ), ), 'pending' => array( 'label' => __( 'Pending item', 'booking' ), 'description' => sprintf( __( 'Activate and type your %1$stitle of pending%2$s item in legend', 'booking' ), '', '' ), 'placeholder' => __( 'Pending', 'booking' ), ), 'approved' => array( 'label' => __( 'Approved item', 'booking' ), 'description' => sprintf( __( 'Activate and type your %1$stitle of approved%2$s item in legend', 'booking' ), '', '' ), 'placeholder' => __( 'Booked', 'booking' ), ), 'partially' => array( 'label' => __( 'Partially booked item', 'booking' ), 'description' => sprintf( __( 'Activate and type your %1$stitle of partially booked%2$s item in legend', 'booking' ), '', '' ), 'placeholder' => __( 'Partially booked', 'booking' ), 'note' => __( 'Partially booked item - day, which is booked for the specific time-slot(s).', 'booking' ), ), 'unavailable' => array( 'label' => __( 'Unavailable item', 'booking' ), 'description' => sprintf( __( 'Activate and type your %1$stitle of unavailable%2$s item in legend', 'booking' ), '', '' ), 'placeholder' => __( 'Unavailable', 'booking' ), ), ); } /** * Normalize week-day CSV. * * @param string|array $value Week days. * * @return string */ function wpbc_settings_calendar__normalize_week_days( $value ) { if ( is_array( $value ) ) { $items = $value; } else { $value = (string) $value; if ( '-1' === $value || '' === $value ) { return '-1'; } $items = explode( ',', $value ); } $cleaned = array(); foreach ( $items as $item ) { $day = (string) absint( $item ); if ( in_array( $day, array( '0', '1', '2', '3', '4', '5', '6' ), true ) ) { $cleaned[] = $day; } } $cleaned = array_values( array_unique( $cleaned ) ); return empty( $cleaned ) ? '-1' : implode( ',', $cleaned ); } /** * Normalize the fixed one-click range length. * * Existing installations may not have this option yet. Keep explicitly * configured values, including one day, but use three days when it is empty * or invalid. * * @param mixed $value Fixed range day count. * * @return int */ function wpbc_settings_calendar__normalize_fixed_range_days_count( $value ) { $days_count = absint( $value ); return ( 0 < $days_count ) ? min( 180, $days_count ) : 3; } /** * Get settings response. * * @return array */ function wpbc_settings_calendar__get_settings_response() { $settings = array( 'booking_max_monthes_in_calendar' => (string) get_bk_option( 'booking_max_monthes_in_calendar' ), 'booking_start_day_weeek' => (string) get_bk_option( 'booking_start_day_weeek' ), 'booking_calendar_allow_several_months_on_mobile' => (string) get_bk_option( 'booking_calendar_allow_several_months_on_mobile' ), 'booking_type_of_day_selections' => (string) get_bk_option( 'booking_type_of_day_selections' ), 'booking_range_selection_type' => (string) get_bk_option( 'booking_range_selection_type' ), 'booking_range_selection_days_count' => (string) wpbc_settings_calendar__normalize_fixed_range_days_count( get_bk_option( 'booking_range_selection_days_count' ) ), 'booking_range_start_day' => wpbc_settings_calendar__normalize_week_days( get_bk_option( 'booking_range_start_day' ) ), 'booking_range_selection_days_count_dynamic' => (string) get_bk_option( 'booking_range_selection_days_count_dynamic' ), 'booking_range_selection_days_max_count_dynamic' => (string) get_bk_option( 'booking_range_selection_days_max_count_dynamic' ), 'booking_range_selection_days_specific_num_dynamic' => (string) get_bk_option( 'booking_range_selection_days_specific_num_dynamic' ), 'booking_range_start_day_dynamic' => wpbc_settings_calendar__normalize_week_days( get_bk_option( 'booking_range_start_day_dynamic' ) ), 'booking_recurrent_time' => (string) get_bk_option( 'booking_recurrent_time' ), 'booking_last_checkout_day_available' => (string) get_bk_option( 'booking_last_checkout_day_available' ), 'booking_range_selection_time_is_active' => (string) get_bk_option( 'booking_range_selection_time_is_active' ), 'booking_range_selection_start_time' => (string) get_bk_option( 'booking_range_selection_start_time' ), 'booking_range_selection_end_time' => (string) get_bk_option( 'booking_range_selection_end_time' ), 'booking_change_over_days_triangles' => (string) get_bk_option( 'booking_change_over_days_triangles' ), 'booking_change_over__is_excerpt_on_pages' => (string) get_bk_option( 'booking_change_over__is_excerpt_on_pages' ), 'booking_change_over__excerpt_on_pages' => (string) get_bk_option( 'booking_change_over__excerpt_on_pages' ), 'booking_change_over__excerpt_bk_resources' => (string) get_bk_option( 'booking_change_over__excerpt_bk_resources' ), 'booking_is_show_legend' => (string) get_bk_option( 'booking_is_show_legend' ), 'booking_legend_is_show_numbers' => (string) get_bk_option( 'booking_legend_is_show_numbers' ), 'booking_legend_is_vertical' => (string) get_bk_option( 'booking_legend_is_vertical' ), 'booking_disable_timeslots_in_tooltip' => (string) get_bk_option( 'booking_disable_timeslots_in_tooltip' ), 'booking_highlight_timeslot_word' => (string) get_bk_option( 'booking_highlight_timeslot_word' ), ); foreach ( wpbc_settings_calendar__get_legend_items_config() as $legend_item => $legend_config ) { $settings[ 'booking_legend_is_show_item_' . $legend_item ] = (string) get_bk_option( 'booking_legend_is_show_item_' . $legend_item ); $settings[ 'booking_legend_text_for_item_' . $legend_item ] = (string) get_bk_option( 'booking_legend_text_for_item_' . $legend_item ); } if ( class_exists( 'wpdev_bk_biz_l' ) ) { $settings['booking_is_show_availability_in_tooltips'] = (string) get_bk_option( 'booking_is_show_availability_in_tooltips' ); $settings['booking_highlight_availability_word'] = (string) get_bk_option( 'booking_highlight_availability_word' ); $settings['booking_is_show_availability_in_date_cell'] = (string) get_bk_option( 'booking_is_show_availability_in_date_cell' ); $settings['booking_highlight_availability_word_in_date_cell'] = (string) get_bk_option( 'booking_highlight_availability_word_in_date_cell' ); } if ( class_exists( 'wpdev_bk_biz_m' ) ) { $settings['booking_is_show_cost_in_tooltips'] = (string) get_bk_option( 'booking_is_show_cost_in_tooltips' ); $settings['booking_highlight_cost_word'] = (string) get_bk_option( 'booking_highlight_cost_word' ); $settings['booking_is_show_cost_in_date_cell'] = (string) get_bk_option( 'booking_is_show_cost_in_date_cell' ); $settings['booking_cost_in_date_cell_currency'] = (string) get_bk_option( 'booking_cost_in_date_cell_currency' ); $settings['booking_is_show_booked_data_in_tooltips'] = (string) get_bk_option( 'booking_is_show_booked_data_in_tooltips' ); $settings['booking_booked_data_in_tooltips'] = (string) get_bk_option( 'booking_booked_data_in_tooltips' ); } return $settings; } /** * Get normalized day-selection settings for the calendar JS. * * @param array $settings Optional settings. * * @return array */ function wpbc_settings_calendar__get_days_selection_response( $settings = array() ) { $current = wp_parse_args( $settings, wpbc_settings_calendar__get_settings_response() ); $specific_days = ( function_exists( 'wpbc_get_specific_range_dates__as_comma_list' ) ) ? wpbc_get_specific_range_dates__as_comma_list( $current['booking_range_selection_days_specific_num_dynamic'] ) : $current['booking_range_selection_days_specific_num_dynamic']; return array( 'days_select_mode' => ( 'range' === $current['booking_type_of_day_selections'] ) ? ( wpbc_settings_calendar__is_range_supported() ? $current['booking_range_selection_type'] : 'dynamic' ) : $current['booking_type_of_day_selections'], 'fixed__days_num' => wpbc_settings_calendar__normalize_fixed_range_days_count( $current['booking_range_selection_days_count'] ), 'fixed__week_days__start' => wpbc_settings_calendar__normalize_week_days( $current['booking_range_start_day'] ), 'dynamic__days_min' => max( 1, absint( $current['booking_range_selection_days_count_dynamic'] ) ), 'dynamic__days_max' => max( 1, absint( $current['booking_range_selection_days_max_count_dynamic'] ) ), 'dynamic__days_specific' => (string) $specific_days, 'dynamic__week_days__start' => wpbc_settings_calendar__normalize_week_days( $current['booking_range_start_day_dynamic'] ), ); } /** * Check whether booked time slots should be shown in calendar tooltips. * * @param array $settings Calendar settings. * * @return bool */ function wpbc_settings_calendar__is_timeslots_tooltip_enabled( $settings ) { return ( 'On' !== (string) $settings['booking_disable_timeslots_in_tooltip'] ); } /** * Override get_bk_option during preview rendering. * * @param mixed $value Current value. * @param string $option Option name. * @param mixed $default Default. * * @return mixed */ function wpbc_settings_calendar__preview_get_bk_option( $value, $option, $default ) { global $wpbc_settings_calendar__preview_options; if ( is_array( $wpbc_settings_calendar__preview_options ) && array_key_exists( $option, $wpbc_settings_calendar__preview_options ) ) { return $wpbc_settings_calendar__preview_options[ $option ]; } return $value; } add_bk_filter( 'wpdev_bk_get_option', 'wpbc_settings_calendar__preview_get_bk_option' ); /** * Override native WordPress options while Calendar Settings preview is active. * * This backs up the internal WPBC option filter for render paths that fall through * to get_option(), without saving preview values into the database. * * @param mixed $pre_option Pre-option value. * @param string $option Option name. * @param mixed $default Default option value. * * @return mixed */ function wpbc_settings_calendar__preview_get_wp_option( $pre_option, $option, $default ) { global $wpbc_settings_calendar__preview_options; if ( is_array( $wpbc_settings_calendar__preview_options ) && array_key_exists( $option, $wpbc_settings_calendar__preview_options ) ) { return $wpbc_settings_calendar__preview_options[ $option ]; } return $pre_option; } /** * Register native option preview filters for the current option set. * * @param array $preview_options Preview option overrides. * * @return void */ function wpbc_settings_calendar__preview_register_wp_option_filters( $preview_options ) { global $wpbc_settings_calendar__preview_wp_option_filters; if ( ! is_array( $preview_options ) ) { return; } if ( ! is_array( $wpbc_settings_calendar__preview_wp_option_filters ) ) { $wpbc_settings_calendar__preview_wp_option_filters = array(); } foreach ( array_keys( $preview_options ) as $option_name ) { $option_name = (string) $option_name; if ( isset( $wpbc_settings_calendar__preview_wp_option_filters[ $option_name ] ) ) { continue; } add_filter( 'pre_option_' . $option_name, 'wpbc_settings_calendar__preview_get_wp_option', 10, 3 ); $wpbc_settings_calendar__preview_wp_option_filters[ $option_name ] = true; } } /** * Activate Calendar Settings preview option overrides. * * @param array $preview_options Preview option overrides. * * @return array Previous preview context. */ function wpbc_settings_calendar__preview_options_push( $preview_options ) { global $wpbc_settings_calendar__preview_options; $previous_context = array( 'is_set' => isset( $wpbc_settings_calendar__preview_options ), 'value' => isset( $wpbc_settings_calendar__preview_options ) ? $wpbc_settings_calendar__preview_options : null, ); $wpbc_settings_calendar__preview_options = is_array( $preview_options ) ? $preview_options : array(); // Re-append while preview is active so this override runs after edition/MU option filters. add_bk_filter( 'wpdev_bk_get_option', 'wpbc_settings_calendar__preview_get_bk_option' ); wpbc_settings_calendar__preview_register_wp_option_filters( $wpbc_settings_calendar__preview_options ); return $previous_context; } /** * Restore Calendar Settings preview option overrides. * * @param array $previous_context Previous preview context from wpbc_settings_calendar__preview_options_push(). * * @return void */ function wpbc_settings_calendar__preview_options_pop( $previous_context ) { global $wpbc_settings_calendar__preview_options; if ( ! empty( $previous_context['is_set'] ) ) { $wpbc_settings_calendar__preview_options = $previous_context['value']; } else { unset( $wpbc_settings_calendar__preview_options ); } } /** * Check whether a calendar-load AJAX request may use Calendar Settings preview overrides. * * @param array $request_params Calendar-load request params. * * @return bool */ function wpbc_settings_calendar__is_calendar_load_preview_request_allowed( $request_params ) { $is_settings_preview_allowed = ( ! empty( $request_params['wpbc_settings_calendar_preview'] ) && function_exists( 'wpbc_is_mu_user_can_be_here' ) && wpbc_is_mu_user_can_be_here( 'only_super_admin' ) && current_user_can( wpbc_settings_calendar__get_manage_cap() ) ); if ( $is_settings_preview_allowed ) { return true; } return ( class_exists( 'WPBC_Setup_Wizard_Date_Selection' ) && WPBC_Setup_Wizard_Date_Selection::is_calendar_preview_request_allowed( (array) $request_params ) ); } /** * Get option overrides from Calendar Settings calendar-load AJAX request. * * @param array $request_params Calendar-load request params. * * @return array */ function wpbc_settings_calendar__get_calendar_load_preview_options( $request_params ) { $preview_options = array( 'booking_range_selection_time_is_active' => isset( $request_params['wpbc_settings_calendar_preview_changeover'] ) ? $request_params['wpbc_settings_calendar_preview_changeover'] : 'Off', 'booking_change_over_days_triangles' => isset( $request_params['wpbc_settings_calendar_preview_triangles'] ) ? $request_params['wpbc_settings_calendar_preview_triangles'] : 'On', 'booking_recurrent_time' => isset( $request_params['wpbc_settings_calendar_preview_recurrent_time'] ) ? $request_params['wpbc_settings_calendar_preview_recurrent_time'] : 'Off', 'booking_last_checkout_day_available' => isset( $request_params['wpbc_settings_calendar_preview_last_checkout'] ) ? $request_params['wpbc_settings_calendar_preview_last_checkout'] : 'Off', 'booking_change_over__is_excerpt_on_pages' => isset( $request_params['wpbc_settings_calendar_preview_excerpt_on_pages'] ) ? $request_params['wpbc_settings_calendar_preview_excerpt_on_pages'] : 'Off', 'booking_change_over__excerpt_on_pages' => isset( $request_params['wpbc_settings_calendar_preview_excerpt_pages'] ) ? $request_params['wpbc_settings_calendar_preview_excerpt_pages'] : '', 'booking_change_over__excerpt_bk_resources' => isset( $request_params['wpbc_settings_calendar_preview_excerpt_resources'] ) ? $request_params['wpbc_settings_calendar_preview_excerpt_resources'] : '', 'booking_is_show_legend' => isset( $request_params['wpbc_settings_calendar_preview_show_legend'] ) ? $request_params['wpbc_settings_calendar_preview_show_legend'] : 'Off', 'booking_legend_is_show_numbers' => isset( $request_params['wpbc_settings_calendar_preview_legend_show_numbers'] ) ? $request_params['wpbc_settings_calendar_preview_legend_show_numbers'] : 'Off', 'booking_legend_is_vertical' => isset( $request_params['wpbc_settings_calendar_preview_legend_vertical'] ) ? $request_params['wpbc_settings_calendar_preview_legend_vertical'] : 'Off', 'booking_disable_timeslots_in_tooltip' => isset( $request_params['wpbc_settings_calendar_preview_disable_timeslots_tooltip'] ) ? $request_params['wpbc_settings_calendar_preview_disable_timeslots_tooltip'] : 'Off', 'booking_highlight_timeslot_word' => isset( $request_params['wpbc_settings_calendar_preview_timeslot_word'] ) ? $request_params['wpbc_settings_calendar_preview_timeslot_word'] : '', ); foreach ( wpbc_settings_calendar__get_legend_items_config() as $legend_item => $legend_config ) { $preview_options[ 'booking_legend_is_show_item_' . $legend_item ] = isset( $request_params[ 'wpbc_settings_calendar_preview_legend_show_' . $legend_item ] ) ? $request_params[ 'wpbc_settings_calendar_preview_legend_show_' . $legend_item ] : 'Off'; $preview_options[ 'booking_legend_text_for_item_' . $legend_item ] = isset( $request_params[ 'wpbc_settings_calendar_preview_legend_text_' . $legend_item ] ) ? $request_params[ 'wpbc_settings_calendar_preview_legend_text_' . $legend_item ] : ''; } if ( class_exists( 'wpdev_bk_biz_l' ) ) { $preview_options['booking_is_show_availability_in_tooltips'] = isset( $request_params['wpbc_settings_calendar_preview_show_availability_tooltip'] ) ? $request_params['wpbc_settings_calendar_preview_show_availability_tooltip'] : 'Off'; $preview_options['booking_highlight_availability_word'] = isset( $request_params['wpbc_settings_calendar_preview_availability_word'] ) ? $request_params['wpbc_settings_calendar_preview_availability_word'] : ''; $preview_options['booking_is_show_availability_in_date_cell'] = isset( $request_params['wpbc_settings_calendar_preview_show_availability_cell'] ) ? $request_params['wpbc_settings_calendar_preview_show_availability_cell'] : 'Off'; $preview_options['booking_highlight_availability_word_in_date_cell'] = isset( $request_params['wpbc_settings_calendar_preview_availability_cell_word'] ) ? $request_params['wpbc_settings_calendar_preview_availability_cell_word'] : ''; } if ( class_exists( 'wpdev_bk_biz_m' ) ) { $preview_options['booking_is_show_cost_in_tooltips'] = isset( $request_params['wpbc_settings_calendar_preview_show_cost_tooltip'] ) ? $request_params['wpbc_settings_calendar_preview_show_cost_tooltip'] : 'Off'; $preview_options['booking_highlight_cost_word'] = isset( $request_params['wpbc_settings_calendar_preview_cost_word'] ) ? $request_params['wpbc_settings_calendar_preview_cost_word'] : ''; $preview_options['booking_is_show_cost_in_date_cell'] = isset( $request_params['wpbc_settings_calendar_preview_show_cost_cell'] ) ? $request_params['wpbc_settings_calendar_preview_show_cost_cell'] : 'Off'; $preview_options['booking_cost_in_date_cell_currency'] = isset( $request_params['wpbc_settings_calendar_preview_cost_currency'] ) ? $request_params['wpbc_settings_calendar_preview_cost_currency'] : ''; $preview_options['booking_is_show_booked_data_in_tooltips'] = isset( $request_params['wpbc_settings_calendar_preview_show_booked_details'] ) ? $request_params['wpbc_settings_calendar_preview_show_booked_details'] : 'Off'; $preview_options['booking_booked_data_in_tooltips'] = isset( $request_params['wpbc_settings_calendar_preview_booked_details'] ) ? $request_params['wpbc_settings_calendar_preview_booked_details'] : ''; } return $preview_options; } /** * Get request overrides for the calendar-load AJAX generated inside Calendar Settings preview. * * @param array $current_settings Current preview settings. * * @return array */ function wpbc_settings_calendar__get_calendar_load_preview_request_overrides( $current_settings ) { $request_overrides = array( 'wpbc_settings_calendar_preview' => 1, 'wpbc_settings_calendar_preview_changeover' => ( 'On' === (string) $current_settings['booking_range_selection_time_is_active'] ) ? 'On' : 'Off', 'wpbc_settings_calendar_preview_triangles' => ( 'Off' === (string) $current_settings['booking_change_over_days_triangles'] ) ? 'Off' : 'On', 'wpbc_settings_calendar_preview_recurrent_time' => ( 'On' === (string) $current_settings['booking_recurrent_time'] ) ? 'On' : 'Off', 'wpbc_settings_calendar_preview_last_checkout' => ( 'On' === (string) $current_settings['booking_last_checkout_day_available'] ) ? 'On' : 'Off', 'wpbc_settings_calendar_preview_excerpt_on_pages' => ( 'On' === (string) $current_settings['booking_change_over__is_excerpt_on_pages'] ) ? 'On' : 'Off', 'wpbc_settings_calendar_preview_excerpt_pages' => (string) $current_settings['booking_change_over__excerpt_on_pages'], 'wpbc_settings_calendar_preview_excerpt_resources' => (string) $current_settings['booking_change_over__excerpt_bk_resources'], 'wpbc_settings_calendar_preview_show_legend' => ( 'On' === (string) $current_settings['booking_is_show_legend'] ) ? 'On' : 'Off', 'wpbc_settings_calendar_preview_legend_show_numbers' => ( 'On' === (string) $current_settings['booking_legend_is_show_numbers'] ) ? 'On' : 'Off', 'wpbc_settings_calendar_preview_legend_vertical' => ( 'On' === (string) $current_settings['booking_legend_is_vertical'] ) ? 'On' : 'Off', 'wpbc_settings_calendar_preview_disable_timeslots_tooltip' => ( 'On' === (string) $current_settings['booking_disable_timeslots_in_tooltip'] ) ? 'On' : 'Off', 'wpbc_settings_calendar_preview_timeslot_word' => (string) $current_settings['booking_highlight_timeslot_word'], ); foreach ( wpbc_settings_calendar__get_legend_items_config() as $legend_item => $legend_config ) { $is_show_key = 'booking_legend_is_show_item_' . $legend_item; $text_key = 'booking_legend_text_for_item_' . $legend_item; if ( isset( $current_settings[ $is_show_key ] ) ) { $request_overrides[ 'wpbc_settings_calendar_preview_legend_show_' . $legend_item ] = ( 'On' === (string) $current_settings[ $is_show_key ] ) ? 'On' : 'Off'; } if ( isset( $current_settings[ $text_key ] ) ) { $request_overrides[ 'wpbc_settings_calendar_preview_legend_text_' . $legend_item ] = (string) $current_settings[ $text_key ]; } } if ( class_exists( 'wpdev_bk_biz_l' ) ) { $request_overrides['wpbc_settings_calendar_preview_show_availability_tooltip'] = ( 'On' === (string) $current_settings['booking_is_show_availability_in_tooltips'] ) ? 'On' : 'Off'; $request_overrides['wpbc_settings_calendar_preview_availability_word'] = (string) $current_settings['booking_highlight_availability_word']; $request_overrides['wpbc_settings_calendar_preview_show_availability_cell'] = ( 'On' === (string) $current_settings['booking_is_show_availability_in_date_cell'] ) ? 'On' : 'Off'; $request_overrides['wpbc_settings_calendar_preview_availability_cell_word'] = (string) $current_settings['booking_highlight_availability_word_in_date_cell']; } if ( class_exists( 'wpdev_bk_biz_m' ) ) { $request_overrides['wpbc_settings_calendar_preview_show_cost_tooltip'] = ( 'On' === (string) $current_settings['booking_is_show_cost_in_tooltips'] ) ? 'On' : 'Off'; $request_overrides['wpbc_settings_calendar_preview_cost_word'] = (string) $current_settings['booking_highlight_cost_word']; $request_overrides['wpbc_settings_calendar_preview_show_cost_cell'] = ( 'On' === (string) $current_settings['booking_is_show_cost_in_date_cell'] ) ? 'On' : 'Off'; $request_overrides['wpbc_settings_calendar_preview_cost_currency'] = (string) $current_settings['booking_cost_in_date_cell_currency']; $request_overrides['wpbc_settings_calendar_preview_show_booked_details'] = ( 'On' === (string) $current_settings['booking_is_show_booked_data_in_tooltips'] ) ? 'On' : 'Off'; $request_overrides['wpbc_settings_calendar_preview_booked_details'] = (string) $current_settings['booking_booked_data_in_tooltips']; } return $request_overrides; } /** * Check change-over state while Calendar Settings preview option overrides are active. * * @param int|string $resource_id Booking resource ID. * @param string|false $request_uri Request URI or false for current URI. * * @return bool|null Boolean when preview context is active, null otherwise. */ function wpbc_settings_calendar__preview_is_changeover_enabled( $resource_id = 0, $request_uri = false ) { global $wpbc_settings_calendar__preview_options; if ( ! is_array( $wpbc_settings_calendar__preview_options ) ) { return null; } if ( ! isset( $wpbc_settings_calendar__preview_options['booking_range_selection_time_is_active'] ) || 'On' !== (string) $wpbc_settings_calendar__preview_options['booking_range_selection_time_is_active'] ) { return false; } if ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) { return wpbc_is_booking_used_check_in_out_time( $request_uri, $resource_id ); } return true; } /** * Validate page data. * * @param array $post_data Raw post data. * * @return array */ function wpbc_settings_calendar__validate_data( $post_data, $is_preview = false ) { $current = wpbc_settings_calendar__get_settings_response(); $max_months = wpbc_settings_calendar__get_max_month_options(); $weekdays = wpbc_settings_calendar__get_weekday_options(); $range_supported = wpbc_settings_calendar__is_range_supported(); $cleaned = array(); $max_monthes = isset( $post_data['booking_max_monthes_in_calendar'] ) ? sanitize_text_field( wp_unslash( $post_data['booking_max_monthes_in_calendar'] ) ) : $current['booking_max_monthes_in_calendar']; $cleaned['booking_max_monthes_in_calendar'] = isset( $max_months[ $max_monthes ] ) ? $max_monthes : '1y'; $start_day = isset( $post_data['booking_start_day_weeek'] ) ? sanitize_key( wp_unslash( $post_data['booking_start_day_weeek'] ) ) : $current['booking_start_day_weeek']; $cleaned['booking_start_day_weeek'] = array_key_exists( $start_day, $weekdays ) ? $start_day : '0'; $cleaned['booking_calendar_allow_several_months_on_mobile'] = ( isset( $post_data['booking_calendar_allow_several_months_on_mobile'] ) && 'On' === wp_unslash( $post_data['booking_calendar_allow_several_months_on_mobile'] ) ) ? 'On' : 'Off'; $day_mode = isset( $post_data['booking_type_of_day_selections'] ) ? sanitize_key( wp_unslash( $post_data['booking_type_of_day_selections'] ) ) : $current['booking_type_of_day_selections']; if ( ! in_array( $day_mode, array( 'single', 'multiple', 'range' ), true ) ) { $day_mode = 'multiple'; } $cleaned['booking_type_of_day_selections'] = $day_mode; $range_type = isset( $post_data['booking_range_selection_type'] ) ? sanitize_key( wp_unslash( $post_data['booking_range_selection_type'] ) ) : $current['booking_range_selection_type']; $cleaned['booking_range_selection_type'] = in_array( $range_type, array( 'fixed', 'dynamic' ), true ) ? $range_type : 'dynamic'; $cleaned['booking_range_selection_days_count'] = (string) wpbc_settings_calendar__normalize_fixed_range_days_count( isset( $post_data['booking_range_selection_days_count'] ) ? wp_unslash( $post_data['booking_range_selection_days_count'] ) : $current['booking_range_selection_days_count'] ); $cleaned['booking_range_selection_days_count_dynamic'] = (string) min( 1095, max( 1, absint( isset( $post_data['booking_range_selection_days_count_dynamic'] ) ? wp_unslash( $post_data['booking_range_selection_days_count_dynamic'] ) : $current['booking_range_selection_days_count_dynamic'] ) ) ); $cleaned['booking_range_selection_days_max_count_dynamic'] = (string) min( 1095, max( 1, absint( isset( $post_data['booking_range_selection_days_max_count_dynamic'] ) ? wp_unslash( $post_data['booking_range_selection_days_max_count_dynamic'] ) : $current['booking_range_selection_days_max_count_dynamic'] ) ) ); if ( (int) $cleaned['booking_range_selection_days_max_count_dynamic'] < (int) $cleaned['booking_range_selection_days_count_dynamic'] ) { $cleaned['booking_range_selection_days_max_count_dynamic'] = $cleaned['booking_range_selection_days_count_dynamic']; } $cleaned['booking_range_selection_days_specific_num_dynamic'] = isset( $post_data['booking_range_selection_days_specific_num_dynamic'] ) ? preg_replace( '/[^0-9,\-\s]/', '', sanitize_text_field( wp_unslash( $post_data['booking_range_selection_days_specific_num_dynamic'] ) ) ) : $current['booking_range_selection_days_specific_num_dynamic']; $fixed_start_mode = isset( $post_data['booking_range_start_day_mode'] ) ? sanitize_key( wp_unslash( $post_data['booking_range_start_day_mode'] ) ) : ( '-1' === $current['booking_range_start_day'] ? '-1' : 'specific' ); $dynamic_start_mode = isset( $post_data['booking_range_start_day_dynamic_mode'] ) ? sanitize_key( wp_unslash( $post_data['booking_range_start_day_dynamic_mode'] ) ) : ( '-1' === $current['booking_range_start_day_dynamic'] ? '-1' : 'specific' ); $cleaned['booking_range_start_day'] = ( '-1' === $fixed_start_mode ) ? '-1' : wpbc_settings_calendar__normalize_week_days( isset( $post_data['booking_range_start_day_weekdays'] ) ? wp_unslash( $post_data['booking_range_start_day_weekdays'] ) : $current['booking_range_start_day'] ); $cleaned['booking_range_start_day_dynamic'] = ( '-1' === $dynamic_start_mode ) ? '-1' : wpbc_settings_calendar__normalize_week_days( isset( $post_data['booking_range_start_day_dynamic_weekdays'] ) ? wp_unslash( $post_data['booking_range_start_day_dynamic_weekdays'] ) : $current['booking_range_start_day_dynamic'] ); $cleaned['booking_recurrent_time'] = ( isset( $post_data['booking_recurrent_time'] ) && 'On' === wp_unslash( $post_data['booking_recurrent_time'] ) ) ? 'On' : 'Off'; $cleaned['booking_last_checkout_day_available'] = ( isset( $post_data['booking_last_checkout_day_available'] ) && 'On' === wp_unslash( $post_data['booking_last_checkout_day_available'] ) ) ? 'On' : 'Off'; $cleaned['booking_range_selection_time_is_active'] = ( isset( $post_data['booking_range_selection_time_is_active'] ) && 'On' === wp_unslash( $post_data['booking_range_selection_time_is_active'] ) ) ? 'On' : 'Off'; $cleaned['booking_change_over_days_triangles'] = ( isset( $post_data['booking_change_over_days_triangles'] ) && 'On' === wp_unslash( $post_data['booking_change_over_days_triangles'] ) ) ? 'On' : 'Off'; $cleaned['booking_change_over__is_excerpt_on_pages'] = ( isset( $post_data['booking_change_over__is_excerpt_on_pages'] ) && 'On' === wp_unslash( $post_data['booking_change_over__is_excerpt_on_pages'] ) ) ? 'On' : 'Off'; foreach ( array( 'booking_range_selection_start_time', 'booking_range_selection_end_time' ) as $time_key ) { $time_value = isset( $post_data[ $time_key ] ) ? sanitize_text_field( wp_unslash( $post_data[ $time_key ] ) ) : $current[ $time_key ]; $cleaned[ $time_key ] = preg_match( '/^\d{2}:\d{2}$/', $time_value ) ? $time_value : $current[ $time_key ]; } $cleaned['booking_change_over__excerpt_on_pages'] = isset( $post_data['booking_change_over__excerpt_on_pages'] ) ? sanitize_textarea_field( wp_unslash( $post_data['booking_change_over__excerpt_on_pages'] ) ) : $current['booking_change_over__excerpt_on_pages']; $cleaned['booking_change_over__excerpt_bk_resources'] = isset( $post_data['booking_change_over__excerpt_bk_resources'] ) ? sanitize_textarea_field( wp_unslash( $post_data['booking_change_over__excerpt_bk_resources'] ) ) : $current['booking_change_over__excerpt_bk_resources']; $cleaned['booking_is_show_legend'] = ( isset( $post_data['booking_is_show_legend'] ) && 'On' === wp_unslash( $post_data['booking_is_show_legend'] ) ) ? 'On' : 'Off'; $cleaned['booking_legend_is_show_numbers'] = ( isset( $post_data['booking_legend_is_show_numbers'] ) && 'On' === wp_unslash( $post_data['booking_legend_is_show_numbers'] ) ) ? 'On' : 'Off'; $cleaned['booking_legend_is_vertical'] = ( isset( $post_data['booking_legend_is_vertical'] ) && 'On' === wp_unslash( $post_data['booking_legend_is_vertical'] ) ) ? 'On' : 'Off'; if ( isset( $post_data['booking_show_timeslots_in_tooltip'] ) ) { $cleaned['booking_disable_timeslots_in_tooltip'] = ( 'On' === wp_unslash( $post_data['booking_show_timeslots_in_tooltip'] ) ) ? 'Off' : 'On'; } else { $cleaned['booking_disable_timeslots_in_tooltip'] = ( isset( $post_data['booking_disable_timeslots_in_tooltip'] ) && 'On' === wp_unslash( $post_data['booking_disable_timeslots_in_tooltip'] ) ) ? 'On' : 'Off'; } $cleaned['booking_highlight_timeslot_word'] = isset( $post_data['booking_highlight_timeslot_word'] ) ? sanitize_text_field( wp_unslash( $post_data['booking_highlight_timeslot_word'] ) ) : $current['booking_highlight_timeslot_word']; foreach ( wpbc_settings_calendar__get_legend_items_config() as $legend_item => $legend_config ) { $is_show_key = 'booking_legend_is_show_item_' . $legend_item; $text_key = 'booking_legend_text_for_item_' . $legend_item; $cleaned[ $is_show_key ] = ( isset( $post_data[ $is_show_key ] ) && 'On' === wp_unslash( $post_data[ $is_show_key ] ) ) ? 'On' : 'Off'; $cleaned[ $text_key ] = isset( $post_data[ $text_key ] ) ? sanitize_text_field( wp_unslash( $post_data[ $text_key ] ) ) : $current[ $text_key ]; } if ( class_exists( 'wpdev_bk_biz_l' ) ) { $cleaned['booking_is_show_availability_in_tooltips'] = ( isset( $post_data['booking_is_show_availability_in_tooltips'] ) && 'On' === wp_unslash( $post_data['booking_is_show_availability_in_tooltips'] ) ) ? 'On' : 'Off'; $cleaned['booking_highlight_availability_word'] = isset( $post_data['booking_highlight_availability_word'] ) ? sanitize_text_field( wp_unslash( $post_data['booking_highlight_availability_word'] ) ) : $current['booking_highlight_availability_word']; $cleaned['booking_is_show_availability_in_date_cell'] = ( isset( $post_data['booking_is_show_availability_in_date_cell'] ) && 'On' === wp_unslash( $post_data['booking_is_show_availability_in_date_cell'] ) ) ? 'On' : 'Off'; $cleaned['booking_highlight_availability_word_in_date_cell'] = isset( $post_data['booking_highlight_availability_word_in_date_cell'] ) ? sanitize_text_field( wp_unslash( $post_data['booking_highlight_availability_word_in_date_cell'] ) ) : $current['booking_highlight_availability_word_in_date_cell']; } if ( class_exists( 'wpdev_bk_biz_m' ) ) { $cleaned['booking_is_show_cost_in_tooltips'] = ( isset( $post_data['booking_is_show_cost_in_tooltips'] ) && 'On' === wp_unslash( $post_data['booking_is_show_cost_in_tooltips'] ) ) ? 'On' : 'Off'; $cleaned['booking_highlight_cost_word'] = isset( $post_data['booking_highlight_cost_word'] ) ? sanitize_text_field( wp_unslash( $post_data['booking_highlight_cost_word'] ) ) : $current['booking_highlight_cost_word']; $cleaned['booking_is_show_cost_in_date_cell'] = ( isset( $post_data['booking_is_show_cost_in_date_cell'] ) && 'On' === wp_unslash( $post_data['booking_is_show_cost_in_date_cell'] ) ) ? 'On' : 'Off'; $cleaned['booking_cost_in_date_cell_currency'] = isset( $post_data['booking_cost_in_date_cell_currency'] ) ? sanitize_text_field( wp_unslash( $post_data['booking_cost_in_date_cell_currency'] ) ) : $current['booking_cost_in_date_cell_currency']; $cleaned['booking_is_show_booked_data_in_tooltips'] = ( isset( $post_data['booking_is_show_booked_data_in_tooltips'] ) && 'On' === wp_unslash( $post_data['booking_is_show_booked_data_in_tooltips'] ) ) ? 'On' : 'Off'; $cleaned['booking_booked_data_in_tooltips'] = isset( $post_data['booking_booked_data_in_tooltips'] ) ? sanitize_text_field( wp_unslash( $post_data['booking_booked_data_in_tooltips'] ) ) : $current['booking_booked_data_in_tooltips']; } if ( ! $is_preview && ! $range_supported ) { foreach ( array( 'booking_range_selection_time_is_active', 'booking_last_checkout_day_available', 'booking_change_over_days_triangles', 'booking_change_over__is_excerpt_on_pages' ) as $premium_key ) { $cleaned[ $premium_key ] = $current[ $premium_key ]; } } return $cleaned; } /** * Update settings. * * @param array $cleaned_data Cleaned data. * * @return void */ function wpbc_settings_calendar__update_settings( $cleaned_data ) { $range_supported = wpbc_settings_calendar__is_range_supported(); $free_keys = array( 'booking_max_monthes_in_calendar', 'booking_start_day_weeek', 'booking_calendar_allow_several_months_on_mobile', 'booking_type_of_day_selections', 'booking_recurrent_time', 'booking_is_show_legend', 'booking_legend_is_show_numbers', 'booking_legend_is_vertical', 'booking_disable_timeslots_in_tooltip', 'booking_highlight_timeslot_word', ); $premium_keys = array( 'booking_range_selection_type', 'booking_range_selection_days_count', 'booking_range_start_day', 'booking_range_selection_days_count_dynamic', 'booking_range_selection_days_max_count_dynamic', 'booking_range_selection_days_specific_num_dynamic', 'booking_range_start_day_dynamic', 'booking_last_checkout_day_available', 'booking_range_selection_time_is_active', 'booking_range_selection_start_time', 'booking_range_selection_end_time', 'booking_change_over_days_triangles', 'booking_change_over__is_excerpt_on_pages', 'booking_change_over__excerpt_on_pages', 'booking_change_over__excerpt_bk_resources', ); $availability_tooltip_keys = array( 'booking_is_show_availability_in_tooltips', 'booking_highlight_availability_word', 'booking_is_show_availability_in_date_cell', 'booking_highlight_availability_word_in_date_cell', ); $cost_tooltip_keys = array( 'booking_is_show_cost_in_tooltips', 'booking_highlight_cost_word', 'booking_is_show_cost_in_date_cell', 'booking_cost_in_date_cell_currency', 'booking_is_show_booked_data_in_tooltips', 'booking_booked_data_in_tooltips', ); foreach ( wpbc_settings_calendar__get_legend_items_config() as $legend_item => $legend_config ) { $free_keys[] = 'booking_legend_is_show_item_' . $legend_item; $free_keys[] = 'booking_legend_text_for_item_' . $legend_item; } $previous_day_mode = (string) get_bk_option( 'booking_type_of_day_selections' ); foreach ( $free_keys as $key ) { update_bk_option( $key, $cleaned_data[ $key ] ); } // Keep a newly selected Free range upgrade-safe: Business Small+ must continue with the same two-click subtype. if ( ! $range_supported && 'range' === $cleaned_data['booking_type_of_day_selections'] && 'range' !== $previous_day_mode ) { update_bk_option( 'booking_range_selection_type', 'dynamic' ); } if ( $range_supported ) { foreach ( $premium_keys as $key ) { update_bk_option( $key, $cleaned_data[ $key ] ); } } if ( class_exists( 'wpdev_bk_biz_l' ) ) { foreach ( $availability_tooltip_keys as $key ) { update_bk_option( $key, $cleaned_data[ $key ] ); } } if ( class_exists( 'wpdev_bk_biz_m' ) ) { foreach ( $cost_tooltip_keys as $key ) { update_bk_option( $key, $cleaned_data[ $key ] ); } } } /** * Render select element. * * @param string $name Name. * @param array $options Options. * @param string $selected Selected value. * @param array $args Arguments. * * @return void */ function wpbc_settings_calendar__render_select( $name, $options, $selected, $args = array() ) { $id = isset( $args['id'] ) ? $args['id'] : $name; $class = isset( $args['class'] ) ? $args['class'] : ''; ?> '×', 'hint' => __( 'Hide this option', 'booking' ), 'css' => 'float:none;margin-left:4px;', ) ); ?>
: