PluginProbe
Booking Calendar / 11.8
Booking Calendar v11.8
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / includes / booking_modes_v3 / booking_modes-toolbar.php

booking_modes-toolbar.php in Booking Calendar 11.8, at includes/booking_modes_v3/booking_modes-toolbar.php

246 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Booking Modes toolbar selector and assets.
4 *
5 * @package Booking Calendar
6 * @since 11.5.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Enqueue the mode selector client on Booking Calendar administration pages.
15 *
16 * @return void
17 */
18 function wpbc_booking_modes_enqueue_toolbar_script() {
19
20 $context = wpbc_booking_modes_get_context();
21
22 if ( ! $context['is_wpbc_page'] || ! wpbc_booking_modes_current_user_can_switch() ) {
23 return;
24 }
25
26 $script_handle = 'wpbc-booking-modes-toolbar';
27 $script_url = trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/booking_modes.js';
28 $selected_mode_id = wpbc_booking_modes_get_selected_mode_id();
29 $selected_mode = wpbc_booking_modes_get_mode( $selected_mode_id );
30 /* translators: %s: Activated Booking Calendar administration mode. */
31 $switch_success_message = is_array( $selected_mode )
32 ? sprintf( __( '%s mode activated.', 'booking' ), $selected_mode['label'] )
33 : __( 'Booking Calendar mode activated.', 'booking' );
34
35 wp_enqueue_script( $script_handle, $script_url, array( 'jquery', 'wpbc_all' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) );
36 wp_localize_script(
37 $script_handle,
38 'wpbc_booking_modes_config',
39 array(
40 'ajax_url' => admin_url( 'admin-ajax.php' ),
41 'action' => 'WPBC_AJX_BOOKING_MODE_SWITCH',
42 'nonce' => wp_create_nonce( 'wpbc_booking_modes_switch_nonce' ),
43 'selected_mode_id' => $selected_mode_id,
44 'quickstart' => function_exists( 'wpbc_booking_modes_run_quickstart' )
45 ? array(
46 'action' => 'WPBC_AJX_BOOKING_MODE_QUICKSTART',
47 'nonce' => wp_create_nonce( 'wpbc_booking_modes_quickstart_nonce' ),
48 )
49 : array(),
50 'i18n' => array(
51 'saving' => __( 'Switching Booking Calendar mode...', 'booking' ),
52 'error' => __( 'The administration mode could not be changed.', 'booking' ),
53 'quickstart_error' => __( 'QuickStart could not be completed.', 'booking' ),
54 'quickstart_confirm' => __( 'QuickStart can create a public booking page and configure mode defaults. Continue?', 'booking' ),
55 'test_page' => __( 'Test booking page', 'booking' ),
56 'switched' => __( 'Booking Calendar mode activated.', 'booking' ),
57 'switch_success' => $switch_success_message,
58 ),
59 )
60 );
61 }
62 add_action( 'wpbc_load_js_on_admin_page', 'wpbc_booking_modes_enqueue_toolbar_script', 30 );
63
64 /**
65 * Enqueue the scoped mode selector stylesheet on Booking Calendar pages.
66 *
67 * @return void
68 */
69 function wpbc_booking_modes_enqueue_toolbar_style() {
70
71 $context = wpbc_booking_modes_get_context();
72
73 if ( ! $context['is_wpbc_page'] || ! wpbc_booking_modes_current_user_can_switch() ) {
74 return;
75 }
76
77 wp_enqueue_style( 'wpbc-booking-modes-toolbar', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/booking_modes.css', array(), WP_BK_VERSION_NUM );
78 }
79 add_action( 'wpbc_load_css_on_admin_page', 'wpbc_booking_modes_enqueue_toolbar_style', 30 );
80
81 /**
82 * Render the administration mode selector in the shared top toolbar.
83 *
84 * @param string $page_tag Current Booking Calendar page slug.
85 * @param string $active_page_tab Current active tab slug.
86 * @param string $active_page_subtab Current active subtab slug.
87 *
88 * @return void
89 */
90 function wpbc_booking_modes_render_toolbar_selector( $page_tag, $active_page_tab, $active_page_subtab ) {
91
92 unset( $page_tag, $active_page_tab, $active_page_subtab );
93
94 if ( ! wpbc_booking_modes_current_user_can_switch() ) {
95 return;
96 }
97
98 $selected_mode_id = wpbc_booking_modes_get_selected_mode_id();
99 $selected_mode = wpbc_booking_modes_get_mode( $selected_mode_id );
100 $selector_items = array();
101
102 foreach ( wpbc_booking_modes_get_allowed_mode_ids() as $mode_id ) {
103 $mode = wpbc_booking_modes_get_mode( $mode_id );
104
105 if ( ! is_array( $mode ) ) {
106 continue;
107 }
108
109 $item_attributes = array(
110 'class' => 'wpbc_booking_mode_option' . ( $selected_mode_id === $mode_id ? ' is-current' : '' ),
111 'data-mode-id' => $mode_id,
112 );
113
114 if ( $selected_mode_id === $mode_id ) {
115 $item_attributes['aria-current'] = 'true';
116 }
117
118 $selector_items[] = array(
119 'type' => 'link',
120 'title' => $mode['label'],
121 'url' => '#',
122 'attr' => $item_attributes,
123 );
124 }
125
126 if ( empty( $selector_items ) || ! is_array( $selected_mode ) ) {
127 return;
128 }
129
130 wpbc_ui_el__divider_vertical( array( 'class' => 'wpbc_booking_modes_toolbar_divider wpbc_ui_el__vertical_line' ) );
131 wpbc_ui_el__dropdown_menu(
132 array(
133 /* translators: %s: Selected Booking Calendar administration mode. */
134 'title' => sprintf( __( 'Mode: %s', 'booking' ), $selected_mode['label'] ),
135 'has_border' => false,
136 'class' => 'wpbc_booking_modes_toggle',
137 'container_class' => 'wpbc_booking_modes_selector',
138 'attr' => array( 'aria-label' => __( 'Booking Calendar administration mode', 'booking' ) ),
139 'items' => $selector_items,
140 )
141 );
142 }
143 add_action( 'wpbc_ui_el__top_nav__content_start', 'wpbc_booking_modes_render_toolbar_selector', 5, 3 );
144
145 /**
146 * Render the explicit QuickStart notice in the floating admin-message stack.
147 *
148 * Mode selection remains a presentation-only operation. QuickStart uses a
149 * standard WordPress notice with standard buttons because it can create site
150 * content. Each mode has a separate user-specific dismissal key, so dismissing
151 * one prompt does not suppress the other. Live demos omit these prompts because
152 * their guided sample content is already provisioned separately.
153 *
154 * @param string $page_tag Current Booking Calendar page slug.
155 * @param string $active_page_tab Current active tab slug.
156 * @param string $active_page_subtab Current active subtab slug.
157 *
158 * @return void
159 */
160 function wpbc_booking_modes_render_quickstart_action( $page_tag, $active_page_tab, $active_page_subtab ) {
161
162 unset( $page_tag, $active_page_tab, $active_page_subtab );
163
164 if ( function_exists( 'wpbc_setup_wizard_page__is_in_progress' ) && wpbc_setup_wizard_page__is_in_progress() ) {
165 return;
166 }
167
168 if ( function_exists( 'wpbc_is_this_demo' ) && wpbc_is_this_demo() ) {
169 return;
170 }
171
172 $mode_id = wpbc_booking_modes_get_selected_mode_id();
173 $mode = wpbc_booking_modes_get_mode( $mode_id );
174
175 if ( ! is_array( $mode ) || empty( $mode['quickstart_id'] ) || 'classic' === $mode_id ) {
176 return;
177 }
178
179 $notice_id = 'wpbc_booking_modes_quickstart_notice_' . $mode_id;
180
181 if ( function_exists( 'wpbc_is_dismissed_panel_visible' ) && ! wpbc_is_dismissed_panel_visible( $notice_id ) ) {
182 return;
183 }
184
185 $notice_title = 'appointment' === $mode_id
186 ? __( 'Appointment QuickStart', 'booking' )
187 : __( 'Rental QuickStart', 'booking' );
188 $notice_text = 'appointment' === $mode_id
189 ? __( 'Create or reuse the first Service, Provider assignment, suitable Booking Form, and Appointment booking page.', 'booking' )
190 : __( 'Configure date ranges and changeover times, then create or reuse the first Property booking page.', 'booking' );
191
192 if ( ! function_exists( 'wpbc_booking_modes_current_user_can_quickstart' ) || ! wpbc_booking_modes_current_user_can_quickstart() ) {
193 return;
194 }
195
196 $test_url = wpbc_booking_modes_get_quickstart_test_url( $mode_id );
197 ?>
198 <div>
199 <div class="wpbc_alert_message">
200 <div id="<?php echo esc_attr( $notice_id ); ?>" class="wpbc_inner_message notice notice-info wpbc_booking_modes_quickstart_notice" data-wpbc-quickstart-mode="<?php echo esc_attr( $mode_id ); ?>">
201 <?php wpbc_booking_modes_render_quickstart_dismiss_button( $notice_id ); ?>
202 <p><strong><?php echo esc_html( $notice_title ); ?></strong></p>
203 <p><?php echo esc_html( $notice_text ); ?></p>
204 <p class="wpbc_booking_modes_quickstart_actions">
205 <button type="button" class="button button-primary wpbc_booking_modes_quickstart_button" data-mode-id="<?php echo esc_attr( $mode_id ); ?>">
206 <?php esc_html_e( 'Run QuickStart', 'booking' ); ?>
207 </button>
208 <a class="button button-secondary wpbc_booking_modes_test_page<?php echo $test_url ? '' : ' is-hidden'; ?>" href="<?php echo esc_url( $test_url ? $test_url : '#' ); ?>" target="_blank" rel="noopener noreferrer">
209 <?php esc_html_e( 'Test booking page', 'booking' ); ?>
210 </a>
211 </p>
212 </div>
213 </div>
214 </div>
215 <?php
216 }
217
218 /**
219 * Render the existing persistent Booking Calendar dismiss control.
220 *
221 * The shared dismissal API saves an owner-specific user option through its
222 * nonce-protected AJAX endpoint. The screen-reader label keeps the visual
223 * close symbol understandable to assistive technology.
224 *
225 * @param string $notice_id HTML ID and persistent dismissal key.
226 *
227 * @return void
228 */
229 function wpbc_booking_modes_render_quickstart_dismiss_button( $notice_id ) {
230
231 if ( ! function_exists( 'wpbc_is_dismissed' ) ) {
232 return;
233 }
234
235 wpbc_is_dismissed(
236 $notice_id,
237 array(
238 'title' => '<span aria-hidden="true">&times;</span><span class="screen-reader-text">' . esc_html__( 'Dismiss', 'booking' ) . '</span>',
239 'hint' => __( 'Dismiss', 'booking' ),
240 'class' => 'close',
241 'is_apply_in_demo' => true,
242 )
243 );
244 }
245 add_action( 'wpbc_inside_ui__admin_messages', 'wpbc_booking_modes_render_quickstart_action', 10, 3 );
246