← All changes
|
includes/page-form-builder/save-load/bfb-form-loader.php
+17
-135
11.1
→
11.8.4
View file →
| @@ -1,23 +1,17 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Booking Form Loader (Builder + Legacy fallback). | |
| 3 | + * Booking Form Loader (Builder storage only). | |
| 4 | 4 | * |
| 5 | 5 | * This helper: |
| 6 | 6 | * - Accepts a logical form identifier (form_slug) + status (and optional form_id). |
| 7 | 7 | * - Asks the Booking Form Builder (BFB) for exported form/content. |
| 8 | - * - If Builder returns nothing, falls back to legacy: | |
| 9 | - * * booking_form / booking_form_show options. | |
| 10 | - * * booking_forms_extended (custom forms). | |
| 11 | - * * simple visual form export (booking_form_visual). | |
| 12 | 8 | * |
| 13 | 9 | * It only returns the **source strings** (shortcodes): |
| 14 | 10 | * - "booking form" (form) – the main form shortcodes. |
| 15 | 11 | * - "Content of booking fields data" (content) – email/content template. |
| 16 | 12 | * |
| 17 | - * Rendering/parsing of shortcodes stays in: | |
| 18 | - * - WPBC_BFB _FormShortcodeEngine (new engine), or | |
| 19 | - * - the legacy HTML generators (simple form free). | |
| 13 | + * Rendering/parsing of shortcodes stays in WPBC_BFB_FormShortcodeEngine. | |
| 20 | 14 | * |
| 21 | 15 | * @package Booking Calendar |
| 22 | 16 | * @subpackage Form Builder |
| 23 | 17 | * @file includes/page-form-builder/save-load/bfb-form-loader.php |
| @@ -34,9 +28,9 @@ | ||
| 34 | 28 | */ |
| 35 | 29 | |
| 36 | 30 | /** |
| 37 | 31 | * Central helper for resolving which booking form configuration |
| 38 | - * should be used on the front-end (Builder vs legacy). | |
| 32 | + * should be used on the front-end. | |
| 39 | 33 | */ |
| 40 | 34 | class WPBC_BFB_Form_Loader { |
| 41 | 35 | |
| 42 | 36 | /** |
| @@ -160,9 +154,9 @@ | ||
| 160 | 154 | return isset( $pair['form'] ) ? $pair['form'] : ''; |
| 161 | 155 | } |
| 162 | 156 | |
| 163 | 157 | /** |
| 164 | - * Internal logic for resolving Builder vs legacy form. | |
| 158 | + * Internal logic for resolving Builder form. | |
| 165 | 159 | * |
| 166 | 160 | * @param array $args Arguments. |
| 167 | 161 | * |
| 168 | 162 | * @return array See self::get_pair(). |
| @@ -229,23 +223,17 @@ | ||
| 229 | 223 | ); |
| 230 | 224 | } |
| 231 | 225 | } |
| 232 | 226 | |
| 227 | + return array( | |
| 228 | + 'form' => '', | |
| 229 | + 'content' => '', | |
| 230 | + 'settings_json' => '', | |
| 231 | + 'source' => 'builder', | |
| 232 | + 'form_slug' => $resolved_slug, | |
| 233 | + ); | |
| 234 | + } | |
| 233 | 235 | |
| 234 | - // --------------------------------------------------------------------- | |
| 235 | - // 2. Fallback to legacy storage (options / usermeta). | |
| 236 | - // --------------------------------------------------------------------- | |
| 237 | - $legacy_pair = $this->load_from_legacy( $args ); | |
| 238 | - | |
| 239 | - return array( | |
| 240 | - 'form' => isset( $legacy_pair['form'] ) ? $legacy_pair['form'] : '', | |
| 241 | - 'content' => isset( $legacy_pair['content'] ) ? $legacy_pair['content'] : '', | |
| 242 | - 'settings_json' => '', // legacy has no per-form settings_json yet. | |
| 243 | - 'source' => 'legacy', | |
| 244 | - 'form_slug' => $resolved_slug, | |
| 245 | - ); | |
| 246 | - } | |
| 247 | - | |
| 248 | 236 | /** |
| 249 | 237 | * Normalize loader status to match DB semantics. |
| 250 | 238 | * |
| 251 | 239 | * Maps generic or legacy-like values (e.g. 'publish') to actual statuses |
| @@ -271,12 +259,12 @@ | ||
| 271 | 259 | return $status; |
| 272 | 260 | } |
| 273 | 261 | |
| 274 | 262 | /** |
| 275 | - * Resolve empty or special slugs into real legacy form names. | |
| 263 | + * Resolve empty or special slugs into real form names. | |
| 276 | 264 | * |
| 277 | 265 | * Examples: |
| 278 | - * - '' or 'auto' => current default custom form for $resource_id (or 'standard'). | |
| 266 | + * - '' or 'auto' => current default custom form for $resource_id (or 'standard'). | |
| 279 | 267 | * - 'standard' => keep as is. |
| 280 | 268 | * |
| 281 | 269 | * @param array $args Loader arguments. |
| 282 | 270 | * |
| @@ -311,10 +299,10 @@ | ||
| 311 | 299 | * |
| 312 | 300 | * The actual lookup is delegated to a filter so that this class |
| 313 | 301 | * does not depend on any concrete BFB DB schema. |
| 314 | 302 | * |
| 315 | - * If Builder is disabled, the table is missing or the requested slug/ID | |
| 316 | - * does not exist, the filter should return the $empty value. | |
| 303 | + * If the table is missing or the requested slug/ID does not exist, the | |
| 304 | + * filter should return the $empty value. | |
| 317 | 305 | * |
| 318 | 306 | * @param array $args Loader arguments. |
| 319 | 307 | * |
| 320 | 308 | * @return array { |
| @@ -373,115 +361,9 @@ | ||
| 373 | 361 | |
| 374 | 362 | return $pair; |
| 375 | 363 | } |
| 376 | 364 | |
| 377 | - /** | |
| 378 | - * Fallback loader that reads forms from legacy options (and MultiUser usermeta). | |
| 379 | - * | |
| 380 | - * It reuses the same mechanisms as your current code: | |
| 381 | - * - Default form: | |
| 382 | - * * booking_form / booking_form_show options. | |
| 383 | - * - Custom forms: | |
| 384 | - * * booking_forms_extended via: | |
| 385 | - * - apply_bk_filter( 'wpdev_get_booking_form', ... ) | |
| 386 | - * - wpbc_get_custom_booking_form() for content. | |
| 387 | - * - Simple mode: | |
| 388 | - * * wpbc_simple_form__get_booking_form__as_shortcodes(). | |
| 389 | - * * wpbc_simple_form__get_form_show__as_shortcodes(). | |
| 390 | - * | |
| 391 | - * @param array $args Loader arguments. | |
| 392 | - * | |
| 393 | - * @return array { | |
| 394 | - * @type string $form Booking form (shortcodes). | |
| 395 | - * @type string $content Content of booking fields data (shortcodes). | |
| 396 | - * } | |
| 397 | - */ | |
| 398 | - protected function load_from_legacy( $args ) { | |
| 399 | - | |
| 400 | - $form_slug = isset( $args['form_slug'] ) ? (string) $args['form_slug'] : 'standard'; | |
| 401 | - | |
| 402 | - // ----------------------------------------------------------------- | |
| 403 | - // 1. Advanced booking form (shortcodes). | |
| 404 | - // ----------------------------------------------------------------- | |
| 405 | - $default_form = get_bk_option( 'booking_form' ); | |
| 406 | - $form = ''; | |
| 407 | - | |
| 408 | - if ( 'standard' === $form_slug || '' === $form_slug ) { | |
| 409 | - | |
| 410 | - // Default standard form. | |
| 411 | - $form = $default_form; | |
| 412 | - | |
| 413 | - } else { | |
| 414 | - | |
| 415 | - // Custom form via existing filter that reads booking_forms_extended. | |
| 416 | - $form = apply_bk_filter( 'wpdev_get_booking_form', $default_form, $form_slug ); | |
| 417 | - } | |
| 418 | - | |
| 419 | - // If still empty, build advanced form from Simple mode visual structure. | |
| 420 | - if ( ( '' === trim( $form ) ) && function_exists( 'wpbc_simple_form__get_booking_form__as_shortcodes' ) ) { | |
| 421 | - $form = wpbc_simple_form__get_booking_form__as_shortcodes(); | |
| 422 | - } | |
| 423 | - | |
| 424 | - // ----------------------------------------------------------------- | |
| 425 | - // 2. "Content of booking fields data" (shortcodes). | |
| 426 | - // ----------------------------------------------------------------- | |
| 427 | - $default_content = get_bk_option( 'booking_form_show' ); | |
| 428 | - $content = ''; | |
| 429 | - | |
| 430 | - if ( 'standard' === $form_slug || '' === $form_slug ) { | |
| 431 | - | |
| 432 | - // Default standard content. | |
| 433 | - $content = $default_content; | |
| 434 | - | |
| 435 | - } else { | |
| 436 | - | |
| 437 | - // Custom content via helper that reads booking_forms_extended[name]['content']. | |
| 438 | - if ( function_exists( 'wpbc_get_custom_booking_form' ) ) { | |
| 439 | - $content = wpbc_get_custom_booking_form( | |
| 440 | - $default_content, | |
| 441 | - $form_slug, | |
| 442 | - false, // Let helper call get_bk_option( 'booking_forms_extended' ) internally. | |
| 443 | - 'content', | |
| 444 | - true // Replace simple HTML shortcodes <r>, <c>, <f>, <l>, <item>. | |
| 445 | - ); | |
| 446 | - } | |
| 447 | - } | |
| 448 | - | |
| 449 | - // If still empty, build content from Simple mode visual structure. | |
| 450 | - if ( ( '' === trim( $content ) ) && function_exists( 'wpbc_simple_form__get_form_show__as_shortcodes' ) ) { | |
| 451 | - $content = wpbc_simple_form__get_form_show__as_shortcodes(); | |
| 452 | - } | |
| 453 | - | |
| 454 | - /** | |
| 455 | - * Final filter over legacy values before returning. | |
| 456 | - * | |
| 457 | - * @param array $pair { | |
| 458 | - * @type string $form Booking form (shortcodes). | |
| 459 | - * @type string $content Content of booking fields data (shortcodes). | |
| 460 | - * } | |
| 461 | - * @param array $args Loader arguments. | |
| 462 | - */ | |
| 463 | - $pair = apply_filters( | |
| 464 | - 'wpbc_bfb_form_loader_legacy', | |
| 465 | - array( | |
| 466 | - 'form' => $form, | |
| 467 | - 'content' => $content, | |
| 468 | - ), | |
| 469 | - $args | |
| 470 | - ); | |
| 471 | - | |
| 472 | - // Ensure expected shape. | |
| 473 | - $pair = wp_parse_args( | |
| 474 | - $pair, | |
| 475 | - array( | |
| 476 | - 'form' => '', | |
| 477 | - 'content' => '', | |
| 478 | - ) | |
| 479 | - ); | |
| 480 | - | |
| 481 | - return $pair; | |
| 482 | - } | |
| 483 | -} | |
| 365 | +} | |
| 484 | 366 | |
| 485 | 367 | |
| 486 | 368 | |
| 487 | 369 | |