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 +21 -88 11.211.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,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,28 +108,21 @@
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 - }
167 -
168 - // If BFB runtime is not present => legacy only.
112 + // If BFB runtime is not present.
169 113 if ( ! class_exists( 'WPBC_BFB_Form_Loader' ) ) {
170 - return self::fallback_to_legacy_or_simple( $legacy_instance );
114 + return self::missing_bfb_result( 'bfb_loader_missing' );
171 115 }
172 116
173 - // If storage is not available => legacy only.
117 + // If storage is not available.
174 118 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 );
119 + return self::missing_bfb_result( 'bfb_storage_missing' );
176 120 }
177 121
178 - // Optional: if table does not exist, skip DB.
122 + // Optional: if table does not exist, return missing.
179 123 if ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) {
180 - return self::fallback_to_legacy_or_simple( $legacy_instance );
124 + return self::missing_bfb_result( 'bfb_table_missing' );
181 125 }
182 126
183 127 // ---------------------------------------------------------------------
184 128 // Step B: determine owner_user_id (MultiUser, filterable).
@@ -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
@@ -268,10 +212,9 @@
268 212 */
269 213 return (array) apply_filters( 'wpbc_fe_form_source_resolution', $result, $req );
270 214 }
271 215
272 - // Not found in DB => legacy fallback (existing behavior).
273 - return self::fallback_to_legacy_or_simple( $legacy_instance );
216 + return self::missing_bfb_result( 'bfb_form_not_found', $fallback_chain );
274 217 }
275 218
276 219 // ---------------------------------------------------------------------
277 220 // Internals
@@ -313,30 +256,22 @@
313 256 );
314 257 }
315 258
316 259 /**
317 - * Legacy/simple fallback result.
260 + * Controlled missing BFB result.
318 261 *
319 - * @param mixed $legacy_instance
262 + * @param string $reason Missing reason.
263 + * @param array $fallback_chain Resolution attempts.
320 264 *
321 265 * @return array
322 266 */
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 -
267 + private static function missing_bfb_result( $reason, $fallback_chain = array() ) {
334 268 return array(
335 - 'engine' => 'simple',
336 - 'apply_after_load_filter' => true,
269 + 'engine' => 'bfb_missing',
270 + 'reason' => (string) $reason,
271 + 'apply_after_load_filter' => false,
337 272 'bfb_loader_args' => array(),
338 - 'fallback_chain' => array(),
273 + 'fallback_chain' => is_array( $fallback_chain ) ? $fallback_chain : array(),
339 274 );
340 275 }
341 276 }
342 277
@@ -438,10 +373,8 @@
438 373 'resource_id' => $resource_id,
439 374 'form_slug' => $form_slug,
440 375 'form_status' => $form_status, // <-- critical: use preview/published
441 376 'custom_params' => $custom_params,
442 - 'legacy_instance' => null,
443 -
444 377 // Future-proof: let filters access the full preview context if they need it.
445 378 'ctx' => $ctx,
446 379 );
447 380