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 +63 -65 11.2.1 → 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,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,30 +108,23 @@
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 - }
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 + }
127 116
128 - // If BFB runtime is not present => legacy only.
129 - if ( ! class_exists( 'WPBC_BFB_Form_Loader' ) ) {
130 - return self::fallback_to_legacy_or_simple( $legacy_instance );
131 - }
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 + }
132 121
133 - // If storage is not available => legacy only.
134 - 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 );
136 - }
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 + }
137 126
138 - // Optional: if table does not exist, skip DB.
139 - if ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) {
140 - return self::fallback_to_legacy_or_simple( $legacy_instance );
141 - }
142 -
143 127 // ---------------------------------------------------------------------
144 128 // Step B: determine owner_user_id (MultiUser, filterable).
145 129 // ---------------------------------------------------------------------
146 130 $owner_user_id = 0;
@@ -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
@@ -219,22 +203,46 @@
219 203 'bfb_loader_args' => $bfb_args,
220 204 'fallback_chain' => $fallback_chain,
221 205 );
222 206
223 - /**
224 - * // Info: Hook for addons. Final override point (future scopes, preview rules, etc).
225 - *
226 - * @param array $result
227 - * @param array $req
228 - */
229 - return (array) apply_filters( 'wpbc_fe_form_source_resolution', $result, $req );
230 - }
231 -
232 - // Not found in DB => legacy fallback (existing behavior).
233 - return self::fallback_to_legacy_or_simple( $legacy_instance );
234 - }
235 -
236 - // ---------------------------------------------------------------------
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 + // ---------------------------------------------------------------------
237 245 // Internals
238 246 // ---------------------------------------------------------------------
239 247
240 248 /**
@@ -273,30 +281,22 @@
273 281 );
274 282 }
275 283
276 284 /**
277 - * Legacy/simple fallback result.
285 + * Controlled missing BFB result.
278 286 *
279 - * @param mixed $legacy_instance
287 + * @param string $reason Missing reason.
288 + * @param array $fallback_chain Resolution attempts.
280 289 *
281 290 * @return array
282 291 */
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 -
292 + private static function missing_bfb_result( $reason, $fallback_chain = array() ) {
294 293 return array(
295 - 'engine' => 'simple',
296 - 'apply_after_load_filter' => true,
294 + 'engine' => 'bfb_missing',
295 + 'reason' => (string) $reason,
296 + 'apply_after_load_filter' => false,
297 297 'bfb_loader_args' => array(),
298 - 'fallback_chain' => array(),
298 + 'fallback_chain' => is_array( $fallback_chain ) ? $fallback_chain : array(),
299 299 );
300 300 }
301 301 }
302 302
@@ -398,10 +398,8 @@
398 398 'resource_id' => $resource_id,
399 399 'form_slug' => $form_slug,
400 400 'form_status' => $form_status, // <-- critical: use preview/published
401 401 'custom_params' => $custom_params,
402 - 'legacy_instance' => null,
403 -
404 402 // Future-proof: let filters access the full preview context if they need it.
405 403 'ctx' => $ctx,
406 404 );
407 405