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/_custom_forms/class-custom-forms-helper.php +100 -56 11.011.8.3 View file →
@@ -25,14 +25,13 @@
25 25 */
26 26 class WPBC_FE_Custom_Form_Helper {
27 27
28 28 /**
29 - * List available booking forms (standard + legacy + BFB).
29 + * List available booking forms from BFB storage.
30 30 *
31 31 * Returned array format:
32 32 * array(
33 33 * 'standard' => array( 'title' => '...', 'engine' => 'standard', 'name' => '' ),
34 - * 'myform' => array( 'title' => '...', 'engine' => 'legacy', 'name' => 'myform' ),
35 34 * 'mybfb' => array( 'title' => '...', 'engine' => 'bfb', 'name' => 'mybfb', 'id' => 12, 'status' => 'published' ),
36 35 * )
37 36 *
38 37 * @param array $params - array(
@@ -38,9 +37,9 @@
38 37 * @param array $params - array(
39 38 * 'include_standard' => true, - include_standard (bool) default true .
40 39 * 'owner_user_id' => 0, - owner_user_id (int) default 0 (0 = no filter) .
41 40 * 'statuses' => array( 'published' ), - statuses (array) default array('published') .
42 - * 'list_mode' => 'auto', - list_mode (string) auto|legacy|bfb|both (default auto) // auto|legacy|bfb|both .
41 + * 'list_mode' => 'bfb', - deprecated; BFB storage is always used.
43 42 * )
44 43 *
45 44 * @return array
46 45 */
@@ -51,9 +50,9 @@
51 50 array(
52 51 'include_standard' => true,
53 52 'owner_user_id' => 0,
54 53 'statuses' => array( 'published' ),
55 - 'list_mode' => 'auto', // auto | legacy | bfb | both.
54 + 'list_mode' => 'bfb',
56 55 )
57 56 );
58 57
59 58 $forms_list_arr = array();
@@ -66,52 +65,11 @@
66 65 'name' => '',
67 66 );
68 67 }
69 68
70 - // Decide list mode.
71 - $list_mode = sanitize_key( (string) $params['list_mode'] );
72 - if ( ! in_array( $list_mode, array( 'auto', 'legacy', 'bfb', 'both' ), true ) ) {
73 - $list_mode = 'auto';
74 - }
69 + // 2) BFB.
70 + if ( ! ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) ) {
75 71
76 - if ( 'auto' === $list_mode ) {
77 - $list_mode = WPBC_Frontend_Settings::is_bfb_enabled( null ) ? 'bfb' : 'legacy';
78 - }
79 -
80 - // 2) Legacy.
81 - if ( in_array( $list_mode, array( 'legacy', 'both' ), true ) ) {
82 -
83 - $legacy_forms = get_bk_option( 'booking_forms_extended' );
84 - $legacy_forms = ( ! empty( $legacy_forms ) ) ? maybe_unserialize( $legacy_forms ) : array();
85 -
86 - if ( is_array( $legacy_forms ) ) {
87 - foreach ( $legacy_forms as $legacy_name => $legacy_data ) {
88 -
89 - $legacy_name = sanitize_text_field( (string) $legacy_name );
90 - if ( '' === $legacy_name || 'standard' === $legacy_name ) {
91 - continue;
92 - }
93 -
94 - $title = $legacy_name;
95 - if ( is_array( $legacy_data ) && isset( $legacy_data['title'] ) ) {
96 - $title = sanitize_text_field( (string) $legacy_data['title'] );
97 - if ( '' === $title ) {
98 - $title = $legacy_name;
99 - }
100 - }
101 -
102 - $forms_list_arr[ $legacy_name ] = array(
103 - 'title' => $title,
104 - 'engine' => 'legacy',
105 - 'name' => $legacy_name,
106 - );
107 - }
108 - }
109 - }
110 -
111 - // 3) BFB.
112 - if ( in_array( $list_mode, array( 'bfb', 'both' ), true ) ) {
113 -
114 72 global $wpdb;
115 73
116 74 $owner_user_id = absint( $params['owner_user_id'] );
117 75
@@ -384,13 +342,8 @@
384 342 * @return void
385 343 */
386 344 public static function wpbc_bfb__custom_booking_forms_list__selectbox_html__in_resource_table( $row_num, $resource ){
387 345
388 - $is_bfb_enabled = (bool) WPBC_Frontend_Settings::is_bfb_enabled( null );
389 - if ( ! $is_bfb_enabled ) {
390 - return;
391 - }
392 -
393 346 // == Legacy | Check if we can be here. ==
394 347 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' );
395 348 if ( ( ! $is_can ) && ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) {
396 349 return;
@@ -670,14 +623,105 @@
670 623 /* Remove second "default custom booking form" of legacy scripts, if enabled BFB. */
671 624 add_action(
672 625 'init',
673 626 function () {
674 - $is_bfb_enabled = (bool) WPBC_Frontend_Settings::is_bfb_enabled( null );
675 - if ( $is_bfb_enabled ) {
676 - remove_action( 'wpbc_resources_table_show_col__customform_field', 'wpbc_resources_table_show_col__customform_field__bm', 10 );
627 + remove_action( 'wpbc_resources_table_show_col__customform_field', 'wpbc_resources_table_show_col__customform_field__bm', 10 );
628 + }
629 +);
630 +
631 +
632 +/**
633 + * Register compatibility wrappers after all Free and Pro PHP files are loaded.
634 + *
635 + * Pro versions before 11.4 declare these functions while loading their legacy
636 + * custom-form module. Waiting until the end of `wpbc_loaded_php_files` lets the
637 + * legacy implementation keep ownership and prevents function redeclaration
638 + * fatals during mixed-version updates.
639 + *
640 + * @return void
641 + */
642 +function wpbc_register_custom_form_compatibility_wrappers() {
643 +
644 + if ( ! function_exists( 'wpbc_get_custom_booking_form' ) ) {
645 + /**
646 + * Compatibility wrapper for older custom-form filters.
647 + *
648 + * @param string $default_return_form_content Default value.
649 + * @param string $custom_form_name Form slug.
650 + * @param mixed $serialized_form_content Deprecated legacy payload. Ignored.
651 + * @param string $what_to_return 'form' or 'content'.
652 + * @param bool $is_replace_simple_html Whether to replace custom HTML shortcodes.
653 + *
654 + * @return string
655 + */
656 + function wpbc_get_custom_booking_form( $default_return_form_content, $custom_form_name, $serialized_form_content = false, $what_to_return = 'content', $is_replace_simple_html = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
657 +
658 + $custom_form_name = sanitize_text_field( (string) $custom_form_name );
659 + if ( '' === $custom_form_name ) {
660 + return $default_return_form_content;
661 + }
662 +
663 + $pair = array();
664 + if ( function_exists( 'wpbc_bfb_get_booking_form_pair' ) ) {
665 + $pair = wpbc_bfb_get_booking_form_pair(
666 + array(
667 + 'form_slug' => $custom_form_name,
668 + 'status' => 'published',
669 + )
670 + );
671 + }
672 +
673 + $value = '';
674 + if ( 'form' === $what_to_return ) {
675 + $value = isset( $pair['form'] ) ? (string) $pair['form'] : '';
676 + } else {
677 + $value = isset( $pair['content'] ) ? (string) $pair['content'] : '';
678 + }
679 +
680 + if ( '' === trim( $value ) ) {
681 + $value = (string) $default_return_form_content;
682 + }
683 +
684 + if ( $is_replace_simple_html ) {
685 + $value = wpbc_bf__replace_custom_html_shortcodes( $value );
686 + }
687 +
688 + return $value;
677 689 }
678 690 }
679 -);
691 +
692 + if ( ! function_exists( 'wpbc_toolbar_btn__form_selection' ) ) {
693 + /**
694 + * Compatibility toolbar wrapper used by older admin screens.
695 + *
696 + * @param array $params Optional select params.
697 + *
698 + * @return void
699 + */
700 + function wpbc_toolbar_btn__form_selection( $params = array() ) {
701 + WPBC_FE_Custom_Form_Helper::wpbc_bfb__custom_booking_forms_list__selectbox_html( $params );
702 + }
703 + }
704 +
705 + if ( ! function_exists( 'wpbc_toolbar_btn__custom_forms_in_settings_fields' ) ) {
706 + /**
707 + * Compatibility toolbar wrapper used by Advanced Cost settings.
708 + *
709 + * @param bool $is_show_add_new_custom_form Deprecated. Ignored.
710 + *
711 + * @return void
712 + */
713 + function wpbc_toolbar_btn__custom_forms_in_settings_fields( $is_show_add_new_custom_form = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
714 + WPBC_FE_Custom_Form_Helper::wpbc_bfb__custom_booking_forms_list__selectbox_html( array( 'on_change' => 'wpbc_change_custom_booking_form_in_url__and_reload(this);' ) );
715 + }
716 + }
717 +}
718 +
719 +if ( did_action( 'wpbc_loaded_php_files' ) ) {
720 + wpbc_register_custom_form_compatibility_wrappers();
721 +} else {
722 + add_action( 'wpbc_loaded_php_files', 'wpbc_register_custom_form_compatibility_wrappers', PHP_INT_MAX );
723 +}
680 724
681 725
682 726 /**
683 727 * Show Selectbox with Custom Forms