PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.3
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 10.11 10.11.2 All 203 releases
← All changes | includes/_front_end/class-fe-form-source-resolver.php +20 -47 11.311.8.3 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,10 +12,10 @@
18 12 if ( ! defined( 'ABSPATH' ) ) {
19 13 exit;
20 14 }
21 15
22 -require_once WPBC_PLUGIN_DIR . '/includes/_front_end/class-fe-settings.php';
23 16
17 +
24 18 /**
25 19 * MultiUser ownership helper (core-safe; MU add-on hooks via filters).
26 20 *
27 21 * @since 11.0.x
@@ -62,9 +56,9 @@
62 56 }
63 57
64 58
65 59 /**
66 - * 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.
67 61 *
68 62 * @since 11.0.x
69 63 */
70 64 class WPBC_FE_Form_Source_Resolver {
@@ -76,12 +70,11 @@
76 70 * - resource_id (int)
77 71 * - form_slug (string) // from shortcode form_type
78 72 * - form_status (string) // published|preview
79 73 * - custom_params (array) // parsed from options parser
80 - * - legacy_instance (wpdev_booking|null) // optional
81 74 *
82 75 * Output:
83 - * - engine: 'bfb_db'|'legacy'|'simple'
76 + * - engine: 'bfb_db'|'bfb_missing'
84 77 * - apply_after_load_filter: bool
85 78 * - bfb_loader_args: array
86 79 * - fallback_chain: array
87 80 *
@@ -97,10 +90,8 @@
97 90 $form_slug_raw = isset( $req['form_slug'] ) ? (string) $req['form_slug'] : '';
98 91 $form_status_raw = isset( $req['form_status'] ) ? (string) $req['form_status'] : '';
99 92 $custom_params = ( isset( $req['custom_params'] ) && is_array( $req['custom_params'] ) ) ? $req['custom_params'] : array();
100 93
101 - $legacy_instance = isset( $req['legacy_instance'] ) ? $req['legacy_instance'] : null;
102 -
103 94 // ---------------------------------------------------------------------
104 95 // Step A: determine slug + status (contract).
105 96 // ---------------------------------------------------------------------
106 97 $form_slug = sanitize_text_field( $form_slug_raw );
@@ -117,28 +108,21 @@
117 108 if ( 'preview' !== $status ) {
118 109 $status = 'published';
119 110 }
120 111
121 - // ---------------------------------------------------------------------
122 - // If BFB is NOT enabled => legacy only (no DB touches).
123 - // ---------------------------------------------------------------------
124 - if ( ! class_exists( 'WPBC_Frontend_Settings' ) || ! WPBC_Frontend_Settings::is_bfb_enabled( null ) ) {
125 - return self::fallback_to_legacy_or_simple( $legacy_instance );
126 - }
127 -
128 - // If BFB runtime is not present => legacy only.
112 + // If BFB runtime is not present.
129 113 if ( ! class_exists( 'WPBC_BFB_Form_Loader' ) ) {
130 - return self::fallback_to_legacy_or_simple( $legacy_instance );
114 + return self::missing_bfb_result( 'bfb_loader_missing' );
131 115 }
132 116
133 - // If storage is not available => legacy only.
117 + // If storage is not available.
134 118 if ( ! class_exists( 'WPBC_BFB_Form_Storage' ) || ! method_exists( 'WPBC_BFB_Form_Storage', 'get_form_row_by_key' ) ) {
135 - return self::fallback_to_legacy_or_simple( $legacy_instance );
119 + return self::missing_bfb_result( 'bfb_storage_missing' );
136 120 }
137 121
138 - // Optional: if table does not exist, skip DB.
122 + // Optional: if table does not exist, return missing.
139 123 if ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) {
140 - return self::fallback_to_legacy_or_simple( $legacy_instance );
124 + return self::missing_bfb_result( 'bfb_table_missing' );
141 125 }
142 126
143 127 // ---------------------------------------------------------------------
144 128 // Step B: determine owner_user_id (MultiUser, filterable).
@@ -181,9 +165,9 @@
181 165 $found = self::try_find_row( $form_slug, $status, $owner_user_id, $fallback_chain );
182 166
183 167
184 168 // If not found, and user is not super booking admin, then find row for "SUPER BOOKING ADMIN".
185 -// 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.
186 170 // if ( ! $found && ( $owner_user_id > 0 ) ) {
187 171 // $found = self::try_find_row( $form_slug, $status, 0, $fallback_chain );
188 172 // }
189 173
@@ -228,10 +212,9 @@
228 212 */
229 213 return (array) apply_filters( 'wpbc_fe_form_source_resolution', $result, $req );
230 214 }
231 215
232 - // Not found in DB => legacy fallback (existing behavior).
233 - return self::fallback_to_legacy_or_simple( $legacy_instance );
216 + return self::missing_bfb_result( 'bfb_form_not_found', $fallback_chain );
234 217 }
235 218
236 219 // ---------------------------------------------------------------------
237 220 // Internals
@@ -273,30 +256,22 @@
273 256 );
274 257 }
275 258
276 259 /**
277 - * Legacy/simple fallback result.
260 + * Controlled missing BFB result.
278 261 *
279 - * @param mixed $legacy_instance
262 + * @param string $reason Missing reason.
263 + * @param array $fallback_chain Resolution attempts.
280 264 *
281 265 * @return array
282 266 */
283 - private static function fallback_to_legacy_or_simple( $legacy_instance ) {
284 -
285 - if ( ( ! empty( $legacy_instance ) ) && ( false !== $legacy_instance->wpdev_bk_personal ) && ( 'On' != get_bk_option( 'booking_is_use_simple_booking_form' ) ) ) {
286 - return array(
287 - 'engine' => 'legacy',
288 - 'apply_after_load_filter' => false,
289 - 'bfb_loader_args' => array(),
290 - 'fallback_chain' => array(),
291 - );
292 - }
293 -
267 + private static function missing_bfb_result( $reason, $fallback_chain = array() ) {
294 268 return array(
295 - 'engine' => 'simple',
296 - 'apply_after_load_filter' => true,
269 + 'engine' => 'bfb_missing',
270 + 'reason' => (string) $reason,
271 + 'apply_after_load_filter' => false,
297 272 'bfb_loader_args' => array(),
298 - 'fallback_chain' => array(),
273 + 'fallback_chain' => is_array( $fallback_chain ) ? $fallback_chain : array(),
299 274 );
300 275 }
301 276 }
302 277
@@ -398,10 +373,8 @@
398 373 'resource_id' => $resource_id,
399 374 'form_slug' => $form_slug,
400 375 'form_status' => $form_status, // <-- critical: use preview/published
401 376 'custom_params' => $custom_params,
402 - 'legacy_instance' => null,
403 -
404 377 // Future-proof: let filters access the full preview context if they need it.
405 378 'ctx' => $ctx,
406 379 );
407 380