From 1c861260b7a30d8af3ec882584e6b7a82b273422 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Sat, 29 Apr 2023 12:15:35 +0600 Subject: [PATCH 1/5] fix: compatibility with the events calendar --- class/post-form-template.php | 49 ++++++++++++ .../the_events_calendar.php | 79 +++++++++++-------- wpuf-functions.php | 2 +- 3 files changed, 95 insertions(+), 35 deletions(-) diff --git a/class/post-form-template.php b/class/post-form-template.php index 72024d947..158402831 100644 --- a/class/post-form-template.php +++ b/class/post-form-template.php @@ -65,6 +65,15 @@ abstract class WPUF_Post_Form_Template { */ protected $form_notifications; + /** + * The datetime format for The Event Calender + * + * @since WPUF_SINCE + * + * @var array + */ + const TIB_DATETIME_FORMAT = 'Y-m-d H:i:s'; + public function __construct() { $this->conditionals = [ 'condition_status' => 'no', @@ -141,6 +150,46 @@ public function is_enabled() { * @return void */ public function after_insert( $post_id, $form_id, $form_settings ) { + // we can return form here if it is not a 'The Event Calender' event + if ( empty( $form_settings['post_type'] ) || 'tribe_events' !== $form_settings['post_type'] ) { + return; + } + + $tribe_api = WP_PLUGIN_DIR . '/the-events-calendar/src/Tribe/API.php'; + + if ( ! file_exists( $tribe_api ) ) { + return; + } + + $event_data = [ + 'EventAllDay' => ! empty( $post_data['_EventAllDay'] ) ? $post_data['_EventAllDay'] : 'yes', + 'EventStartDate' => ! empty( $post_data['_EventStartDate'] ) ? $post_data['_EventStartDate'] : wpuf_current_datetime()->format( self::TIB_DATETIME_FORMAT ), + 'EventEndDate' => ! empty( $post_data['_EventEndDate'] ) ? $post_data['_EventEndDate'] : wpuf_current_datetime()->format( self::TIB_DATETIME_FORMAT ), + ]; + + require_once $tribe_api; + + /** + * Opportunity to change 'The Event Calendar' metadata just before WPUF is saving it to DB + * + * @since WPUF_SINCE + * + * @param array $event_data The event metadata + * @param int $post_id The post id, in other words, The Event + * + */ + $event_data = apply_filters( 'wpuf_tib_event_meta', $event_data, $post_id ); + Tribe__Events__API::saveEventMeta( $post_id, $event_data ); + + /** + * Hook fired just after WPUF is saved 'The Event Calender' metadata to the DB + * + * @since WPUF_SINCE + * + * @param int $post_id The post_id, in other words, the event_id + * + */ + do_action( 'wpuf_tib_after_saving_event_meta', $post_id ); } /** diff --git a/includes/free/post-form-templates/the_events_calendar.php b/includes/free/post-form-templates/the_events_calendar.php index d117f4eb4..098b72ba8 100644 --- a/includes/free/post-form-templates/the_events_calendar.php +++ b/includes/free/post-form-templates/the_events_calendar.php @@ -74,49 +74,60 @@ public function __construct() { 'wpuf_cond' => $this->conditionals, ], [ - 'input_type' => 'radio', - 'template' => 'radio_field', - 'required' => 'no', - 'label' => __( 'All Day Event', 'wp-user-frontend' ), - 'name' => '_EventAllDay', - 'is_meta' => 'yes', - 'selected' => [], - 'inline' => 'yes', - 'options' => [ + 'input_type' => 'radio', + 'template' => 'radio_field', + 'required' => 'no', + 'label' => __( 'All Day Event', 'wpuf-pro' ), + 'name' => '_EventAllDay', + 'is_meta' => 'yes', + 'inline' => 'yes', + 'options' => [ 'yes' => 'Yes', 'no' => 'No', ], - 'wpuf_cond' => $this->conditionals, + 'wpuf_cond' => $this->conditionals, + 'wpuf_visibility' => $this->get_default_visibility_prop(), ], [ - 'input_type' => 'url', - 'template' => 'website_url', - 'required' => 'no', - 'label' => __( 'Event Website', 'wp-user-frontend' ), - 'name' => '_EventURL', - 'is_meta' => 'yes', - 'width' => 'large', - 'size' => 40, - 'wpuf_cond' => $this->conditionals, + 'input_type' => 'url', + 'template' => 'website_url', + 'required' => 'no', + 'label' => __( 'Event Website', 'wpuf-pro' ), + 'name' => '_EventURL', + 'is_meta' => 'yes', + 'placeholder' => '', + 'default' => '', + 'width' => 'large', + 'size' => 40, + 'wpuf_cond' => $this->conditionals, + 'wpuf_visibility' => $this->get_default_visibility_prop(), ], [ - 'input_type' => 'text', - 'template' => 'text_field', - 'required' => 'no', - 'label' => __( 'Currency Symbol', 'wp-user-frontend' ), - 'name' => '_EventCurrencySymbol', - 'is_meta' => 'yes', - 'size' => 40, - 'wpuf_cond' => $this->conditionals, + 'input_type' => 'text', + 'template' => 'text_field', + 'required' => 'no', + 'label' => __( 'Currency Symbol', 'wpuf-pro' ), + 'name' => '_EventCurrencySymbol', + 'is_meta' => 'yes', + 'default' => '', + 'placeholder' => '', + 'size' => '', + 'wpuf_cond' => $this->conditionals, + 'wpuf_visibility' => $this->get_default_visibility_prop(), ], [ - 'input_type' => 'text', - 'template' => 'text_field', - 'required' => 'no', - 'label' => __( 'Cost', 'wp-user-frontend' ), - 'name' => '_EventCost', - 'is_meta' => 'yes', - 'wpuf_cond' => $this->conditionals, + 'input_type' => 'text', + 'template' => 'text_field', + 'required' => 'no', + 'label' => __( 'Cost', 'wpuf-pro' ), + 'name' => '_EventCost', + 'is_meta' => 'yes', + 'default' => '', + 'placeholder' => '', + 'size' => '', + 'help' => 'Enter a 0 for events that are free or leave blank to hide the field.', + 'wpuf_cond' => $this->conditionals, + 'wpuf_visibility' => $this->get_default_visibility_prop(), ], [ 'input_type' => 'image_upload', diff --git a/wpuf-functions.php b/wpuf-functions.php index 34685e736..46f416588 100644 --- a/wpuf-functions.php +++ b/wpuf-functions.php @@ -1866,7 +1866,7 @@ function taxnomy_select( $terms, $attr ) { /** * Returns form setting value * - * @param init $form_id + * @param int $form_id * @param boolen $status * * @return array From 0f215d162091e6ac4cec428e16c9fbc194674758 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Sun, 30 Apr 2023 02:11:33 +0600 Subject: [PATCH 2/5] update variable type in doc --- class/post-form-template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/post-form-template.php b/class/post-form-template.php index 158402831..5b1cf5ac7 100644 --- a/class/post-form-template.php +++ b/class/post-form-template.php @@ -70,7 +70,7 @@ abstract class WPUF_Post_Form_Template { * * @since WPUF_SINCE * - * @var array + * @var string */ const TIB_DATETIME_FORMAT = 'Y-m-d H:i:s'; From b746158bc51fa6c75c149da6d1b037a4a395a040 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Thu, 11 May 2023 23:21:52 +0600 Subject: [PATCH 3/5] fix: venue and organizer field and frontend --- .../assets/js/components/field-option-data/index.js | 3 ++- .../assets/js/components/field-option-data/template.php | 3 +-- assets/js-templates/form-components.php | 3 +-- assets/js/wpuf-form-builder-components.js | 3 ++- includes/class-frontend-render-form.php | 2 +- includes/fields/class-abstract-fields.php | 4 +++- includes/fields/class-field-dropdown.php | 4 ++-- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/admin/form-builder/assets/js/components/field-option-data/index.js b/admin/form-builder/assets/js/components/field-option-data/index.js index c3c8d6804..77d5c59d4 100644 --- a/admin/form-builder/assets/js/components/field-option-data/index.js +++ b/admin/form-builder/assets/js/components/field-option-data/index.js @@ -14,7 +14,8 @@ Vue.component('field-option-data', { show_value: false, sync_value: true, options: [], - selected: [] + selected: [], + display: !this.editing_form_field.hide_option_data // hide this field for the events calendar }; }, diff --git a/admin/form-builder/assets/js/components/field-option-data/template.php b/admin/form-builder/assets/js/components/field-option-data/template.php index 1b083fd6a..8f9b38432 100644 --- a/admin/form-builder/assets/js/components/field-option-data/template.php +++ b/admin/form-builder/assets/js/components/field-option-data/template.php @@ -1,4 +1,4 @@ -
+
{{ option_field.title }}
    @@ -40,7 +40,6 @@
     
-
  • diff --git a/assets/js-templates/form-components.php b/assets/js-templates/form-components.php index 6aae8f297..bba46ef54 100644 --- a/assets/js-templates/form-components.php +++ b/assets/js-templates/form-components.php @@ -118,7 +118,7 @@