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 +115 -92 11.411.8.3 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * Description.
4 4 *
@@ -25,9 +25,9 @@
25 25 */
26 26 class WPBC_FE_Custom_Form_Helper {
27 27
28 28 /**
29 - * List available booking forms from BFB storage.
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' => '' ),
@@ -37,9 +37,9 @@
37 37 * @param array $params - array(
38 38 * 'include_standard' => true, - include_standard (bool) default true .
39 39 * 'owner_user_id' => 0, - owner_user_id (int) default 0 (0 = no filter) .
40 40 * 'statuses' => array( 'published' ), - statuses (array) default array('published') .
41 - * 'list_mode' => 'bfb', - deprecated; BFB storage is always used.
41 + * 'list_mode' => 'bfb', - deprecated; BFB storage is always used.
42 42 * )
43 43 *
44 44 * @return array
45 45 */
@@ -50,9 +50,9 @@
50 50 array(
51 51 'include_standard' => true,
52 52 'owner_user_id' => 0,
53 53 'statuses' => array( 'published' ),
54 - 'list_mode' => 'bfb',
54 + 'list_mode' => 'bfb',
55 55 )
56 56 );
57 57
58 58 $forms_list_arr = array();
@@ -65,13 +65,13 @@
65 65 'name' => '',
66 66 );
67 67 }
68 68
69 - // 2) BFB.
70 - if ( ! ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) ) {
71 -
72 - global $wpdb;
69 + // 2) BFB.
70 + if ( ! ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) ) {
73 71
72 + global $wpdb;
73 +
74 74 $owner_user_id = absint( $params['owner_user_id'] );
75 75
76 76 $statuses = ( isset( $params['statuses'] ) && is_array( $params['statuses'] ) ) ? $params['statuses'] : array();
77 77 $statuses = array_values( array_filter( array_map( 'sanitize_key', $statuses ) ) );
@@ -120,9 +120,9 @@
120 120 'owner_user_id' => isset( $row['owner_user_id'] ) ? absint( $row['owner_user_id'] ) : 0,
121 121 );
122 122 }
123 123 }
124 - }
124 + }
125 125
126 126 return $forms_list_arr;
127 127 }
128 128
@@ -342,10 +342,10 @@
342 342 * @return void
343 343 */
344 344 public static function wpbc_bfb__custom_booking_forms_list__selectbox_html__in_resource_table( $row_num, $resource ){
345 345
346 - // == Legacy | Check if we can be here. ==
347 - $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' );
346 + // == Legacy | Check if we can be here. ==
347 + $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' );
348 348 if ( ( ! $is_can ) && ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) {
349 349 return;
350 350 }
351 351
@@ -620,90 +620,113 @@
620 620 }
621 621
622 622 add_action( 'wpbc_resources_table_show_col__customform_field', array( 'WPBC_FE_Custom_Form_Helper', 'wpbc_bfb__custom_booking_forms_list__selectbox_html__in_resource_table' ), 11, 2 );
623 623 /* Remove second "default custom booking form" of legacy scripts, if enabled BFB. */
624 -add_action(
625 - 'init',
626 - function () {
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 - * Compatibility wrapper for older custom-form filters.
634 - *
635 - * @param string $default_return_form_content Default value.
636 - * @param string $custom_form_name Form slug.
637 - * @param mixed $serialized_form_content Deprecated legacy payload. Ignored.
638 - * @param string $what_to_return 'form' or 'content'.
639 - * @param bool $is_replace_simple_html Whether to replace custom HTML shortcodes.
640 - *
641 - * @return string
642 - */
643 -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
644 -
645 - $custom_form_name = sanitize_text_field( (string) $custom_form_name );
646 - if ( '' === $custom_form_name ) {
647 - return $default_return_form_content;
648 - }
649 -
650 - $pair = array();
651 - if ( function_exists( 'wpbc_bfb_get_booking_form_pair' ) ) {
652 - $pair = wpbc_bfb_get_booking_form_pair(
653 - array(
654 - 'form_slug' => $custom_form_name,
655 - 'status' => 'published',
656 - )
657 - );
658 - }
659 -
660 - $value = '';
661 - if ( 'form' === $what_to_return ) {
662 - $value = isset( $pair['form'] ) ? (string) $pair['form'] : '';
663 - } else {
664 - $value = isset( $pair['content'] ) ? (string) $pair['content'] : '';
665 - }
666 -
667 - if ( '' === trim( $value ) ) {
668 - $value = (string) $default_return_form_content;
669 - }
670 -
671 - if ( $is_replace_simple_html ) {
672 - $value = wpbc_bf__replace_custom_html_shortcodes( $value );
673 - }
674 -
675 - return $value;
676 -}
677 -
678 -
679 -/**
680 - * Compatibility toolbar wrapper used by older admin screens.
681 - *
682 - * @param array $params Optional select params.
683 - *
684 - * @return void
685 - */
686 -function wpbc_toolbar_btn__form_selection( $params = array() ) {
687 - WPBC_FE_Custom_Form_Helper::wpbc_bfb__custom_booking_forms_list__selectbox_html( $params );
688 -}
689 -
690 -
691 -/**
692 - * Compatibility toolbar wrapper used by Advanced Cost settings.
693 - *
694 - * @param bool $is_show_add_new_custom_form Deprecated. Ignored.
695 - *
696 - * @return void
697 - */
698 -function wpbc_toolbar_btn__custom_forms_in_settings_fields( $is_show_add_new_custom_form = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
699 - 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);' ) );
700 -}
701 -
702 -
703 -/**
704 - * Show Selectbox with Custom Forms
705 - *
624 +add_action(
625 + 'init',
626 + function () {
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;
689 + }
690 + }
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 +}
724 +
725 +
726 +/**
727 + * Show Selectbox with Custom Forms
728 + *
706 729 * @param $booking_forms_extended
707 730 * @param $on_change
708 731 * @param $params
709 732 *