← All changes
|
includes/booking-appointment/booking-appointment__render.php
+35
-7
11.8.3
→
11.9
View file →
| @@ -550,14 +550,16 @@ | ||
| 550 | 550 | * calendar initialization for markup that will subsequently be discarded. |
| 551 | 551 | * |
| 552 | 552 | * @param string $form_slug Resolved form slug. |
| 553 | 553 | * @param int $provider_id Provider resource ID. |
| 554 | + * @param string $form_status Form source status: published or preview. | |
| 554 | 555 | * |
| 555 | 556 | * @return bool True when Start Time is present or an extension allows the form. |
| 556 | 557 | */ |
| 557 | -function wpbc_booking_appointment_form_has_start_time( $form_slug, $provider_id ) { | |
| 558 | +function wpbc_booking_appointment_form_has_start_time( $form_slug, $provider_id, $form_status = 'published' ) { | |
| 558 | 559 | global $wpdb; |
| 559 | 560 | |
| 561 | + $form_status = 'preview' === sanitize_key( (string) $form_status ) ? 'preview' : 'published'; | |
| 560 | 562 | $has_start_time = false; |
| 561 | 563 | if ( class_exists( 'WPBC_FE_Form_Source_Resolver' ) ) { |
| 562 | 564 | $resolution = WPBC_FE_Form_Source_Resolver::resolve( |
| 563 | 565 | array( |
| @@ -562,13 +564,17 @@ | ||
| 562 | 564 | $resolution = WPBC_FE_Form_Source_Resolver::resolve( |
| 563 | 565 | array( |
| 564 | 566 | 'resource_id' => absint( $provider_id ), |
| 565 | 567 | 'form_slug' => sanitize_text_field( $form_slug ), |
| 566 | - 'form_status' => 'published', | |
| 568 | + 'form_status' => $form_status, | |
| 567 | 569 | ) |
| 568 | 570 | ); |
| 569 | 571 | $form_id = ! empty( $resolution['bfb_loader_args']['form_id'] ) ? absint( $resolution['bfb_loader_args']['form_id'] ) : 0; |
| 570 | - if ( $form_id ) { | |
| 572 | + if ( 'preview' === $form_status && ! empty( $resolution['bfb_loader_args'] ) && function_exists( 'wpbc_bfb_get_booking_form_pair' ) ) { | |
| 573 | + $form_pair = wpbc_bfb_get_booking_form_pair( $resolution['bfb_loader_args'] ); | |
| 574 | + $form_source = is_array( $form_pair ) && isset( $form_pair['form'] ) ? (string) $form_pair['form'] : ''; | |
| 575 | + $has_start_time = false !== stripos( $form_source, 'starttime' ); | |
| 576 | + } elseif ( $form_id ) { | |
| 571 | 577 | $form_source = $wpdb->get_var( $wpdb->prepare( "SELECT advanced_form FROM {$wpdb->prefix}booking_form_structures WHERE booking_form_id = %d AND status = %s LIMIT 1", $form_id, 'published' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 572 | 578 | $has_start_time = is_string( $form_source ) && false !== stripos( $form_source, 'starttime' ); |
| 573 | 579 | } |
| 574 | 580 | } |
| @@ -655,11 +661,27 @@ | ||
| 655 | 661 | */ |
| 656 | 662 | function wpbc_booking_appointment_render_booking_form( $service, $provider, $config, $config_token ) { |
| 657 | 663 | $provider_id = absint( $provider['provider_id'] ); |
| 658 | 664 | $form_slug = wpbc_booking_appointment_resolve_form_slug( $service, $provider_id, $config ); |
| 665 | + /** | |
| 666 | + * Filters the Form Builder source status used by an Appointment form. | |
| 667 | + * | |
| 668 | + * The normal public workflow always uses a published form. The authenticated | |
| 669 | + * Form Builder preview service temporarily changes this to `preview` only for | |
| 670 | + * an exact, user-bound transient snapshot. | |
| 671 | + * | |
| 672 | + * @param string $form_status Existing source status. Default `published`. | |
| 673 | + * @param string $form_slug Resolved Form Builder slug. | |
| 674 | + * @param int $provider_id Selected Provider resource ID. | |
| 675 | + * @param array<string,mixed> $config Signed Appointment shortcode configuration. | |
| 676 | + */ | |
| 677 | + $filtered_form_status = apply_filters( 'wpbc_booking_appointment_form_status', 'published', $form_slug, $provider_id, $config ); | |
| 678 | + $form_status = is_scalar( $filtered_form_status ) && 'preview' === sanitize_key( (string) $filtered_form_status ) | |
| 679 | + ? 'preview' | |
| 680 | + : 'published'; | |
| 659 | 681 | $allow_past = wpbc_booking_appointment_is_past_booking_enabled( $config ); |
| 660 | 682 | $require_start_time = (bool) apply_filters( 'wpbc_booking_appointment_require_start_time', true, $service, $provider, $form_slug ); |
| 661 | - if ( $require_start_time && ! wpbc_booking_appointment_form_has_start_time( $form_slug, $provider_id ) ) { | |
| 683 | + if ( $require_start_time && ! wpbc_booking_appointment_form_has_start_time( $form_slug, $provider_id, $form_status ) ) { | |
| 662 | 684 | $error_data = array(); |
| 663 | 685 | $service_settings_url = wpbc_booking_appointment_get_service_form_settings_url( $service['service_id'] ); |
| 664 | 686 | if ( $service_settings_url ) { |
| 665 | 687 | $error_data = array( |
| @@ -680,20 +702,26 @@ | ||
| 680 | 702 | return new WP_Error( 'appointment_duplicate_provider_form', __( 'This Provider already has an open Appointment form on this page. Complete or restart that Appointment before opening another form for the same Provider.', 'booking' ) ); |
| 681 | 703 | } |
| 682 | 704 | $rendered_provider_ids[ $provider_id ] = true; |
| 683 | 705 | |
| 706 | + $calendar_request_overrides = class_exists( 'WPBC_BFB_Preview_Service' ) | |
| 707 | + ? WPBC_BFB_Preview_Service::get_instance()->get_current_preview_calendar_request_overrides() | |
| 708 | + : array(); | |
| 709 | + // Appointment policy remains authoritative for past-date access while the | |
| 710 | + // signed preview supplies only its allow-listed Date Selection draft values. | |
| 711 | + $calendar_request_overrides['allow_past'] = $allow_past ? 1 : 0; | |
| 712 | + | |
| 684 | 713 | $render_params = array( |
| 685 | 714 | 'is_echo' => 0, |
| 686 | 715 | 'resource_id' => $provider_id, |
| 687 | 716 | 'cal_count' => absint( $config['cal_count'] ), |
| 688 | 717 | 'custom_booking_form' => $form_slug, |
| 718 | + 'form_status' => $form_status, | |
| 689 | 719 | 'shortcode_param__options' => $config['options'], |
| 690 | 720 | 'calendar_dates_start' => $config['calendar_dates_start'], |
| 691 | 721 | 'calendar_dates_end' => $config['calendar_dates_end'], |
| 692 | 722 | 'booking_workflow' => 'appointment', |
| 693 | - 'calendar_request_overrides' => array( | |
| 694 | - 'allow_past' => $allow_past ? 1 : 0, | |
| 695 | - ), | |
| 723 | + 'calendar_request_overrides' => $calendar_request_overrides, | |
| 696 | 724 | ); |
| 697 | 725 | if ( ! empty( $config['start_month_calendar'] ) && is_array( $config['start_month_calendar'] ) ) { |
| 698 | 726 | $render_params['start_month_calendar'] = array( |
| 699 | 727 | absint( $config['start_month_calendar'][0] ), |