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
← All changes | includes/_front_end/class-fe-form-source-resolver.php +64 -106 11.0 → 11.9 View file →
@@ -1,16 +1,10 @@
1 1 <?php
2 2 /**
3 3 * Front-End Booking Form Source Resolver
4 4 *
5 - * Decides which engine to use to build the booking form body:
6 - * - bfb_db : load exported shortcodes from booking_form_structures (only when BFB enabled)
7 - * - legacy : use legacy wpdev_bk_personal->get_booking_form()
8 - * - simple : fallback wpbc_simple_form__get_booking_form__as_html()
5 + * Decides which BFB source to use to build the booking form body.
9 6 *
10 - * Keeps legacy behavior by default:
11 - * - If BFB is disabled => never touches DB and returns legacy/simple only.
12 - *
13 7 * @package Booking Calendar
14 8 * @since 11.0.x
15 9 * @file ../includes/_front_end/class-fe-form-source-resolver.php
16 10 */
@@ -18,8 +12,10 @@
18 12 if ( ! defined( 'ABSPATH' ) ) {
19 13 exit;
20 14 }
21 15
16 +
17 +
22 18 /**
23 19 * MultiUser ownership helper (core-safe; MU add-on hooks via filters).
24 20 *
25 21 * @since 11.0.x
@@ -60,51 +56,9 @@
60 56 }
61 57
62 58
63 59 /**
64 - * Check if we enabled BFB in Settings, e.g.: WPBC_Frontend_Settings::is_bfb_enabled()
65 - */
66 -class WPBC_Frontend_Settings {
67 -
68 - /**
69 - * Is the BFB feature compiled/available in this build.
70 - *
71 - * @return bool
72 - */
73 - public static function is_bfb_feature_available() {
74 - return ( defined( 'WPBC_NEW_FORM_BUILDER' ) && WPBC_NEW_FORM_BUILDER );
75 - }
76 -
77 - /**
78 - * Is BFB enabled in settings.
79 - *
80 - * @param WPBC_Frontend_Context|null $ctx Optional, for future use (preview context etc).
81 - *
82 - * @return bool
83 - */
84 - public static function is_bfb_enabled( $ctx = null ) {
85 -
86 - if ( ! self::is_bfb_feature_available() ) {
87 - return false;
88 - }
89 -
90 - $is_enabled = ( 'On' === get_bk_option( 'booking_use_bfb_form' ) );
91 -
92 - /**
93 - * Allow forcing enable/disable externally if needed.
94 - *
95 - * @param bool $is_enabled
96 - * @param WPBC_Frontend_Context|null $ctx
97 - */
98 - $is_enabled = (bool) apply_filters( 'wpbc_frontend_is_bfb_enabled', $is_enabled, $ctx );
99 -
100 - return $is_enabled;
101 - }
102 -}
103 -
104 -
105 -/**
106 - * Resolver: decides BFB vs legacy vs simple and returns normalized loader args.
60 + * Resolver: decides which BFB row to use and returns normalized loader args.
107 61 *
108 62 * @since 11.0.x
109 63 */
110 64 class WPBC_FE_Form_Source_Resolver {
@@ -116,12 +70,11 @@
116 70 * - resource_id (int)
117 71 * - form_slug (string) // from shortcode form_type
118 72 * - form_status (string) // published|preview
119 73 * - custom_params (array) // parsed from options parser
120 - * - legacy_instance (wpdev_booking|null) // optional
121 74 *
122 75 * Output:
123 - * - engine: 'bfb_db'|'legacy'|'simple'
76 + * - engine: 'bfb_db'|'bfb_missing'
124 77 * - apply_after_load_filter: bool
125 78 * - bfb_loader_args: array
126 79 * - fallback_chain: array
127 80 *
@@ -137,10 +90,8 @@
137 90 $form_slug_raw = isset( $req['form_slug'] ) ? (string) $req['form_slug'] : '';
138 91 $form_status_raw = isset( $req['form_status'] ) ? (string) $req['form_status'] : '';
139 92 $custom_params = ( isset( $req['custom_params'] ) && is_array( $req['custom_params'] ) ) ? $req['custom_params'] : array();
140 93
141 - $legacy_instance = isset( $req['legacy_instance'] ) ? $req['legacy_instance'] : null;
142 -
143 94 // ---------------------------------------------------------------------
144 95 // Step A: determine slug + status (contract).
145 96 // ---------------------------------------------------------------------
146 97 $form_slug = sanitize_text_field( $form_slug_raw );
@@ -157,30 +108,23 @@
157 108 if ( 'preview' !== $status ) {
158 109 $status = 'published';
159 110 }
160 111
161 - // ---------------------------------------------------------------------
162 - // If BFB is NOT enabled => legacy only (no DB touches).
163 - // ---------------------------------------------------------------------
164 - if ( ! class_exists( 'WPBC_Frontend_Settings' ) || ! WPBC_Frontend_Settings::is_bfb_enabled( null ) ) {
165 - return self::fallback_to_legacy_or_simple( $legacy_instance );
166 - }
112 + // If BFB runtime is not present.
113 + if ( ! class_exists( 'WPBC_BFB_Form_Loader' ) ) {
114 + return self::filter_resolution( self::missing_bfb_result( 'bfb_loader_missing' ), $req );
115 + }
167 116
168 - // If BFB runtime is not present => legacy only.
169 - if ( ! class_exists( 'WPBC_BFB_Form_Loader' ) ) {
170 - return self::fallback_to_legacy_or_simple( $legacy_instance );
171 - }
117 + // If storage is not available.
118 + if ( ! class_exists( 'WPBC_BFB_Form_Storage' ) || ! method_exists( 'WPBC_BFB_Form_Storage', 'get_form_row_by_key' ) ) {
119 + return self::filter_resolution( self::missing_bfb_result( 'bfb_storage_missing' ), $req );
120 + }
172 121
173 - // If storage is not available => legacy only.
174 - if ( ! class_exists( 'WPBC_BFB_Form_Storage' ) || ! method_exists( 'WPBC_BFB_Form_Storage', 'get_form_row_by_key' ) ) {
175 - return self::fallback_to_legacy_or_simple( $legacy_instance );
176 - }
122 + // Optional: if table does not exist, return missing.
123 + if ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) {
124 + return self::filter_resolution( self::missing_bfb_result( 'bfb_table_missing' ), $req );
125 + }
177 126
178 - // Optional: if table does not exist, skip DB.
179 - if ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) {
180 - return self::fallback_to_legacy_or_simple( $legacy_instance );
181 - }
182 -
183 127 // ---------------------------------------------------------------------
184 128 // Step B: determine owner_user_id (MultiUser, filterable).
185 129 // ---------------------------------------------------------------------
186 130 $owner_user_id = 0;
@@ -221,9 +165,9 @@
221 165 $found = self::try_find_row( $form_slug, $status, $owner_user_id, $fallback_chain );
222 166
223 167
224 168 // If not found, and user is not super booking admin, then find row for "SUPER BOOKING ADMIN".
225 -// INFO: block this falback. 2026-03-05 20:25. Do not fallback to supr booking admin user. Fallback to legacy mode, instead.
169 +// INFO: block this fallback. 2026-03-05 20:25. Do not fallback to super booking admin user.
226 170 // if ( ! $found && ( $owner_user_id > 0 ) ) {
227 171 // $found = self::try_find_row( $form_slug, $status, 0, $fallback_chain );
228 172 // }
229 173
@@ -259,22 +203,46 @@
259 203 'bfb_loader_args' => $bfb_args,
260 204 'fallback_chain' => $fallback_chain,
261 205 );
262 206
263 - /**
264 - * // Info: Hook for addons. Final override point (future scopes, preview rules, etc).
265 - *
266 - * @param array $result
267 - * @param array $req
268 - */
269 - return (array) apply_filters( 'wpbc_fe_form_source_resolution', $result, $req );
270 - }
271 -
272 - // Not found in DB => legacy fallback (existing behavior).
273 - return self::fallback_to_legacy_or_simple( $legacy_instance );
274 - }
275 -
276 - // ---------------------------------------------------------------------
207 + return self::filter_resolution( $result, $req );
208 + }
209 +
210 + return self::filter_resolution( self::missing_bfb_result( 'bfb_form_not_found', $fallback_chain ), $req );
211 + }
212 +
213 + /**
214 + * Apply the final source-resolution extension point to every outcome.
215 + *
216 + * Preview and other non-persistent sources may be authoritative even when a
217 + * matching database row does not exist. Applying the filter to both resolved
218 + * and missing results lets those sources participate without creating a
219 + * temporary Form Builder record.
220 + *
221 + * @param array $result Normalized resolver result.
222 + * @param array $req Original normalized request context.
223 + *
224 + * @return array Filtered resolver result.
225 + */
226 + private static function filter_resolution( $result, $req ) {
227 +
228 + $result = is_array( $result ) ? $result : array();
229 + $req = is_array( $req ) ? $req : array();
230 +
231 + /**
232 + * Filter the final booking-form source resolution.
233 + *
234 + * This hook runs for successful database resolutions and controlled missing
235 + * results so authenticated, non-persistent sources can provide a complete
236 + * replacement contract.
237 + *
238 + * @param array $result Normalized resolver result.
239 + * @param array $req Source request context.
240 + */
241 + return (array) apply_filters( 'wpbc_fe_form_source_resolution', $result, $req );
242 + }
243 +
244 + // ---------------------------------------------------------------------
277 245 // Internals
278 246 // ---------------------------------------------------------------------
279 247
280 248 /**
@@ -313,30 +281,22 @@
313 281 );
314 282 }
315 283
316 284 /**
317 - * Legacy/simple fallback result.
285 + * Controlled missing BFB result.
318 286 *
319 - * @param mixed $legacy_instance
287 + * @param string $reason Missing reason.
288 + * @param array $fallback_chain Resolution attempts.
320 289 *
321 290 * @return array
322 291 */
323 - private static function fallback_to_legacy_or_simple( $legacy_instance ) {
324 -
325 - if ( ( ! empty( $legacy_instance ) ) && ( false !== $legacy_instance->wpdev_bk_personal ) && ( 'On' != get_bk_option( 'booking_is_use_simple_booking_form' ) ) ) {
326 - return array(
327 - 'engine' => 'legacy',
328 - 'apply_after_load_filter' => false,
329 - 'bfb_loader_args' => array(),
330 - 'fallback_chain' => array(),
331 - );
332 - }
333 -
292 + private static function missing_bfb_result( $reason, $fallback_chain = array() ) {
334 293 return array(
335 - 'engine' => 'simple',
336 - 'apply_after_load_filter' => true,
294 + 'engine' => 'bfb_missing',
295 + 'reason' => (string) $reason,
296 + 'apply_after_load_filter' => false,
337 297 'bfb_loader_args' => array(),
338 - 'fallback_chain' => array(),
298 + 'fallback_chain' => is_array( $fallback_chain ) ? $fallback_chain : array(),
339 299 );
340 300 }
341 301 }
342 302
@@ -438,10 +398,8 @@
438 398 'resource_id' => $resource_id,
439 399 'form_slug' => $form_slug,
440 400 'form_status' => $form_status, // <-- critical: use preview/published
441 401 'custom_params' => $custom_params,
442 - 'legacy_instance' => null,
443 -
444 402 // Future-proof: let filters access the full preview context if they need it.
445 403 'ctx' => $ctx,
446 404 );
447 405