WPBC_JS_IN_FOOTER ) ); wp_localize_script( $script_handle, 'wpbc_booking_modes_config', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'action' => 'WPBC_AJX_BOOKING_MODE_SWITCH', 'nonce' => wp_create_nonce( 'wpbc_booking_modes_switch_nonce' ), 'selected_mode_id' => $selected_mode_id, 'quickstart' => function_exists( 'wpbc_booking_modes_run_quickstart' ) ? array( 'action' => 'WPBC_AJX_BOOKING_MODE_QUICKSTART', 'nonce' => wp_create_nonce( 'wpbc_booking_modes_quickstart_nonce' ), ) : array(), 'i18n' => array( 'saving' => __( 'Switching Booking Calendar mode...', 'booking' ), 'error' => __( 'The administration mode could not be changed.', 'booking' ), 'quickstart_error' => __( 'QuickStart could not be completed.', 'booking' ), 'quickstart_confirm' => __( 'QuickStart can create a public booking page and configure mode defaults. Continue?', 'booking' ), 'test_page' => __( 'Test booking page', 'booking' ), 'switched' => __( 'Booking Calendar mode activated.', 'booking' ), 'switch_success' => $switch_success_message, ), ) ); } add_action( 'wpbc_load_js_on_admin_page', 'wpbc_booking_modes_enqueue_toolbar_script', 30 ); /** * Enqueue the scoped mode selector stylesheet on Booking Calendar pages. * * @return void */ function wpbc_booking_modes_enqueue_toolbar_style() { $context = wpbc_booking_modes_get_context(); if ( ! $context['is_wpbc_page'] || ! wpbc_booking_modes_current_user_can_switch() ) { return; } wp_enqueue_style( 'wpbc-booking-modes-toolbar', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/booking_modes.css', array(), WP_BK_VERSION_NUM ); } add_action( 'wpbc_load_css_on_admin_page', 'wpbc_booking_modes_enqueue_toolbar_style', 30 ); /** * Render the administration mode selector in the shared top toolbar. * * @param string $page_tag Current Booking Calendar page slug. * @param string $active_page_tab Current active tab slug. * @param string $active_page_subtab Current active subtab slug. * * @return void */ function wpbc_booking_modes_render_toolbar_selector( $page_tag, $active_page_tab, $active_page_subtab ) { unset( $page_tag, $active_page_tab, $active_page_subtab ); if ( ! wpbc_booking_modes_current_user_can_switch() ) { return; } $selected_mode_id = wpbc_booking_modes_get_selected_mode_id(); $selected_mode = wpbc_booking_modes_get_mode( $selected_mode_id ); $selector_items = array(); foreach ( wpbc_booking_modes_get_allowed_mode_ids() as $mode_id ) { $mode = wpbc_booking_modes_get_mode( $mode_id ); if ( ! is_array( $mode ) ) { continue; } $item_attributes = array( 'class' => 'wpbc_booking_mode_option' . ( $selected_mode_id === $mode_id ? ' is-current' : '' ), 'data-mode-id' => $mode_id, ); if ( $selected_mode_id === $mode_id ) { $item_attributes['aria-current'] = 'true'; } $selector_items[] = array( 'type' => 'link', 'title' => $mode['label'], 'url' => '#', 'attr' => $item_attributes, ); } if ( empty( $selector_items ) || ! is_array( $selected_mode ) ) { return; } wpbc_ui_el__divider_vertical( array( 'class' => 'wpbc_booking_modes_toolbar_divider wpbc_ui_el__vertical_line' ) ); wpbc_ui_el__dropdown_menu( array( /* translators: %s: Selected Booking Calendar administration mode. */ 'title' => sprintf( __( 'Mode: %s', 'booking' ), $selected_mode['label'] ), 'has_border' => false, 'class' => 'wpbc_booking_modes_toggle', 'container_class' => 'wpbc_booking_modes_selector', 'attr' => array( 'aria-label' => __( 'Booking Calendar administration mode', 'booking' ) ), 'items' => $selector_items, ) ); } add_action( 'wpbc_ui_el__top_nav__content_start', 'wpbc_booking_modes_render_toolbar_selector', 5, 3 ); /** * Render the explicit QuickStart notice in the floating admin-message stack. * * Mode selection remains a presentation-only operation. QuickStart uses a * standard WordPress notice with standard buttons because it can create site * content. Each mode has a separate user-specific dismissal key, so dismissing * one prompt does not suppress the other. Live demos omit these prompts because * their guided sample content is already provisioned separately. * * @param string $page_tag Current Booking Calendar page slug. * @param string $active_page_tab Current active tab slug. * @param string $active_page_subtab Current active subtab slug. * * @return void */ function wpbc_booking_modes_render_quickstart_action( $page_tag, $active_page_tab, $active_page_subtab ) { unset( $page_tag, $active_page_tab, $active_page_subtab ); if ( function_exists( 'wpbc_setup_wizard_page__is_in_progress' ) && wpbc_setup_wizard_page__is_in_progress() ) { return; } if ( function_exists( 'wpbc_is_this_demo' ) && wpbc_is_this_demo() ) { return; } $mode_id = wpbc_booking_modes_get_selected_mode_id(); $mode = wpbc_booking_modes_get_mode( $mode_id ); if ( ! is_array( $mode ) || empty( $mode['quickstart_id'] ) || 'classic' === $mode_id ) { return; } $notice_id = 'wpbc_booking_modes_quickstart_notice_' . $mode_id; if ( function_exists( 'wpbc_is_dismissed_panel_visible' ) && ! wpbc_is_dismissed_panel_visible( $notice_id ) ) { return; } $notice_title = 'appointment' === $mode_id ? __( 'Appointment QuickStart', 'booking' ) : __( 'Rental QuickStart', 'booking' ); $notice_text = 'appointment' === $mode_id ? __( 'Create or reuse the first Service, Provider assignment, suitable Booking Form, and Appointment booking page.', 'booking' ) : __( 'Configure date ranges and changeover times, then create or reuse the first Property booking page.', 'booking' ); if ( ! function_exists( 'wpbc_booking_modes_current_user_can_quickstart' ) || ! wpbc_booking_modes_current_user_can_quickstart() ) { return; } $test_url = wpbc_booking_modes_get_quickstart_test_url( $mode_id ); ?>
'' . esc_html__( 'Dismiss', 'booking' ) . '', 'hint' => __( 'Dismiss', 'booking' ), 'class' => 'close', 'is_apply_in_demo' => true, ) ); } add_action( 'wpbc_inside_ui__admin_messages', 'wpbc_booking_modes_render_quickstart_action', 10, 3 );