PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
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 / page-setup-wizard / class-wpbc-setup-wizard-settings-hints.php

class-wpbc-setup-wizard-settings-hints.php in Booking Calendar 11.9, at includes/page-setup-wizard/class-wpbc-setup-wizard-settings-hints.php

264 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Canonical administration destinations for Setup Wizard settings hints.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Build data-only breadcrumb hints for settings that remain editable later.
14 *
15 * The Setup Wizard owns the relationship between a setup step and the normal
16 * administration page that maintains the same setting. Existing URL helpers
17 * remain authoritative for page, tab, section, and request-local launch
18 * parameters. No request value participates in destination selection.
19 */
20 final class WPBC_Setup_Wizard_Settings_Hints {
21
22 /**
23 * Return the steps that intentionally omit a later-settings hint.
24 *
25 * These pages either collect wizard-only guidance, select the route, or form
26 * the final approval boundary. They do not have one equivalent settings page.
27 *
28 * @return string[] Stable omitted step identifiers.
29 */
30 public function get_omitted_step_ids() {
31 return array(
32 'welcome',
33 'business_details',
34 'date_time_formats',
35 'booking_experience',
36 'customer_journey',
37 'review_setup',
38 );
39 }
40
41 /**
42 * Return a normalized hint for one allow-listed Setup Wizard step.
43 *
44 * @param string $step_id Stable Setup Wizard step identifier.
45 *
46 * @return array{message:string,links:array<int,array{label:string,url:string}>}|array{} Hint data or an empty array.
47 */
48 public function get_hint( $step_id ) {
49 $step_id = sanitize_key( is_scalar( $step_id ) ? (string) $step_id : '' );
50
51 if ( in_array( $step_id, $this->get_omitted_step_ids(), true ) ) {
52 return array();
53 }
54
55 $hint_links = $this->get_hint_links( $step_id );
56
57 if ( empty( $hint_links ) ) {
58 return array();
59 }
60
61 $links = array();
62 foreach ( $hint_links as $link ) {
63 $label = isset( $link[0] ) && is_scalar( $link[0] ) ? sanitize_text_field( (string) $link[0] ) : '';
64 $url = isset( $link[1] ) && is_scalar( $link[1] ) ? esc_url_raw( (string) $link[1] ) : '';
65 if ( '' !== $label && '' !== $url ) {
66 $links[] = array(
67 'label' => $label,
68 'url' => $url,
69 );
70 }
71 }
72
73 if ( empty( $links ) ) {
74 return array();
75 }
76
77 return array(
78 'message' => __( 'You can always change these settings later', 'booking' ),
79 'links' => $links,
80 );
81 }
82
83 /**
84 * Build the breadcrumb pairs for one supported step only.
85 *
86 * Resolving destinations lazily avoids invoking helpers owned by unrelated
87 * administration pages while another Setup Wizard step is rendering.
88 *
89 * @param string $step_id Sanitized Setup Wizard step identifier.
90 *
91 * @return array<int,array{0:string,1:string}> Ordered breadcrumb pairs.
92 */
93 private function get_hint_links( $step_id ) {
94 $supported_step_ids = array(
95 'date_selection',
96 'services',
97 'booking_resources',
98 'start_end_times',
99 'start_duration_times',
100 'fixed_time_slots',
101 'working_hours',
102 'days_off',
103 'booking_form_template',
104 'appearance',
105 'publish_integration',
106 );
107
108 if ( ! in_array( $step_id, $supported_step_ids, true ) ) {
109 return array();
110 }
111
112 $root_url = $this->get_bookings_url();
113
114 switch ( $step_id ) {
115 case 'date_selection':
116 $settings_url = $this->get_settings_url();
117
118 return array(
119 array( __( 'WP Booking Calendar', 'booking' ), $root_url ),
120 array( __( 'Settings', 'booking' ), $settings_url ),
121 array( __( 'Calendar', 'booking' ), $this->get_calendar_url() ),
122 array( __( 'Days Selection', 'booking' ), $this->get_calendar_section_url( 'selection' ) ),
123 );
124
125 case 'services':
126 return array(
127 array( __( 'WP Booking Calendar', 'booking' ), $root_url ),
128 array( __( 'Services', 'booking' ), admin_url( 'admin.php?page=wpbc-services' ) ),
129 );
130
131 case 'booking_resources':
132 $resources_url = $this->get_resources_url();
133
134 return array(
135 array( __( 'WP Booking Calendar', 'booking' ), $root_url ),
136 array( __( 'Resources', 'booking' ), $resources_url ),
137 array( __( 'Booking Resources', 'booking' ), add_query_arg( 'tab', 'resources', $resources_url ) ),
138 );
139
140 case 'start_end_times':
141 case 'start_duration_times':
142 case 'fixed_time_slots':
143 case 'booking_form_template':
144 return $this->get_booking_form_path( $root_url, $this->get_settings_url() );
145
146 case 'working_hours':
147 return array(
148 array( __( 'WP Booking Calendar', 'booking' ), $root_url ),
149 array( __( 'Availability', 'booking' ), $this->get_availability_url() ),
150 array( __( 'Schedule & Rules', 'booking' ), $this->get_working_hours_url() ),
151 );
152
153 case 'days_off':
154 $availability_url = $this->get_availability_url();
155
156 return array(
157 array( __( 'WP Booking Calendar', 'booking' ), $root_url ),
158 array( __( 'Availability', 'booking' ), $availability_url ),
159 array( __( 'Block Dates', 'booking' ), $availability_url ),
160 );
161
162 case 'appearance':
163 return array(
164 array( __( 'WP Booking Calendar', 'booking' ), $root_url ),
165 array( __( 'Settings', 'booking' ), $this->get_settings_url() ),
166 array( __( 'Appearance / Theme', 'booking' ), $this->get_appearance_url() ),
167 );
168
169 case 'publish_integration':
170 $resources_url = $this->get_resources_url();
171 $booking_resources_url = add_query_arg( 'tab', 'resources', $resources_url );
172
173 return array(
174 array( __( 'WP Booking Calendar', 'booking' ), $root_url ),
175 array( __( 'Resources', 'booking' ), $resources_url ),
176 array( __( 'Booking Resources', 'booking' ), $booking_resources_url ),
177 array( __( 'Publishing', 'booking' ), $this->get_publishing_url() ),
178 );
179 }
180
181 return array();
182 }
183
184 /**
185 * Return the repeated Booking Form Builder breadcrumb.
186 *
187 * Time-choice pages write their selections into the canonical Standard form
188 * at the later Booking Form boundary, so Form Builder is their durable editor.
189 *
190 * @param string $root_url Canonical Booking Calendar root URL.
191 * @param string $settings_url Canonical Settings URL.
192 *
193 * @return array<int,array{0:string,1:string}> Ordered breadcrumb pairs.
194 */
195 private function get_booking_form_path( $root_url, $settings_url ) {
196 return array(
197 array( __( 'WP Booking Calendar', 'booking' ), $root_url ),
198 array( __( 'Settings', 'booking' ), $settings_url ),
199 array( __( 'Booking Form Builder', 'booking' ), add_query_arg( 'tab', 'builder_booking_form', $settings_url ) ),
200 );
201 }
202
203 /** @return string Canonical Booking Calendar root URL. */
204 private function get_bookings_url() {
205 return function_exists( 'wpbc_get_bookings_url' ) ? wpbc_get_bookings_url() : admin_url( 'admin.php?page=wpbc' );
206 }
207
208 /** @return string Canonical Settings URL. */
209 private function get_settings_url() {
210 return function_exists( 'wpbc_get_settings_url' ) ? wpbc_get_settings_url() : admin_url( 'admin.php?page=wpbc-settings' );
211 }
212
213 /** @return string Canonical Calendar settings URL. */
214 private function get_calendar_url() {
215 return function_exists( 'wpbc_get_settings_calendar_url' ) ? wpbc_get_settings_calendar_url() : admin_url( 'admin.php?page=wpbc-settings&tab=calendar_settings' );
216 }
217
218 /**
219 * Return one canonical Calendar settings section URL.
220 *
221 * @param string $section Allow-listed Calendar section key.
222 *
223 * @return string Calendar section URL.
224 */
225 private function get_calendar_section_url( $section ) {
226 return function_exists( 'wpbc_settings_calendar__get_section_url' )
227 ? wpbc_settings_calendar__get_section_url( $section )
228 : add_query_arg( 'wpbc_calendar_section', sanitize_key( $section ), $this->get_calendar_url() );
229 }
230
231 /** @return string Canonical Availability URL. */
232 private function get_availability_url() {
233 return function_exists( 'wpbc_get_availability_url' ) ? wpbc_get_availability_url() : admin_url( 'admin.php?page=wpbc-availability' );
234 }
235
236 /** @return string Canonical Schedule and Rules URL with Working Time expanded. */
237 private function get_working_hours_url() {
238 $availability_url = function_exists( 'wpbc_get_general_availability_url' )
239 ? wpbc_get_general_availability_url()
240 : admin_url( 'admin.php?page=wpbc-availability&tab=general_availability' );
241
242 return add_query_arg( 'wpbc_ag_open', 'working_time', $availability_url );
243 }
244
245 /** @return string Canonical Booking Resources URL. */
246 private function get_resources_url() {
247 return function_exists( 'wpbc_get_resources_url' ) ? wpbc_get_resources_url() : admin_url( 'admin.php?page=wpbc-resources' );
248 }
249
250 /** @return string Canonical Appearance and Theme URL. */
251 private function get_appearance_url() {
252 return function_exists( 'wpbc_get_settings_themes_url' ) ? wpbc_get_settings_themes_url() : admin_url( 'admin.php?page=wpbc-settings&tab=themes' );
253 }
254
255 /** @return string Canonical request-local Booking Resource publishing URL. */
256 private function get_publishing_url() {
257 if ( function_exists( 'wpbc_catalog_booking_resources_get_publish_url' ) ) {
258 return wpbc_catalog_booking_resources_get_publish_url();
259 }
260
261 return add_query_arg( 'tab', 'resources', $this->get_resources_url() );
262 }
263 }
264