Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: events calendar post form integration #1494

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,41 @@ public function __construct() {
'wpuf_cond' => $this->conditionals,
],
[
'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', 'wp-user-frontend' ),
'name' => '_EventURL',
'placeholder' => '',
'default' => '',
'is_meta' => 'yes',
'width' => 'large',
'size' => 40,
'wpuf_cond' => $this->conditionals,
],
[
'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', 'wp-user-frontend' ),
'name' => '_EventCurrencySymbol',
'placeholder' => '',
'default' => '',
'is_meta' => 'yes',
'size' => 40,
'wpuf_cond' => $this->conditionals,
],
[
'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', 'wp-user-frontend' ),
'name' => '_EventCost',
'placeholder' => '',
'default' => '',
'size' => 40,
'is_meta' => 'yes',
'wpuf_cond' => $this->conditionals,
Comment on lines +97 to +131
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider implementing form field validation

The URL and cost fields lack validation rules. Consider adding:

  • URL format validation for _EventURL
  • Numeric validation for _EventCost
  • Currency symbol length restriction for _EventCurrencySymbol

Example implementation for the EventURL field:

 'input_type'  => 'url',
 'template'    => 'website_url',
 'required'    => 'no',
 'label'       => __( 'Event Website', 'wp-user-frontend' ),
 'name'        => '_EventURL',
 'placeholder' => '',
 'default'     => '',
 'is_meta'     => 'yes',
 'width'       => 'large',
 'size'        => 40,
+`validate`    => 'url',
 'wpuf_cond'   => $this->conditionals,

Committable suggestion was skipped due to low confidence.

],
[
'input_type' => 'image_upload',
Expand Down
2 changes: 2 additions & 0 deletions includes/Fields/Form_Field_Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WeDevs\Wpuf\Fields;

use WP_Query;

/**
* DropDown Field Class
*/
Expand All @@ -24,17 +26,17 @@
* @return void
*/
public function render( $field_settings, $form_id, $type = 'post', $post_id = null ) {
if ( isset( $post_id ) && $post_id != '0' ) {

Check warning on line 29 in includes/Fields/Form_Field_Dropdown.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "!=="; Found: "!="
$selected = $this->get_meta( $post_id, $field_settings['name'], $type );
} else {
$selected = isset( $field_settings['selected'] ) ? $field_settings['selected'] : '';
}

/* Workaround for Events calendar venue and organizer field render in wpuf custom fields metabox */
if ( 'tribe_events' == get_post_type( $post_id ) ) {

Check warning on line 36 in includes/Fields/Form_Field_Dropdown.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
if ( '_EventVenueID' == $field_settings['name'] ) {

Check warning on line 37 in includes/Fields/Form_Field_Dropdown.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
$field_settings['options'] = $this->get_posts( 'tribe_venue' );
} else if ( '_EventOrganizerID' == $field_settings['name'] ) {

Check warning on line 39 in includes/Fields/Form_Field_Dropdown.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Usage of ELSE IF is discouraged; use ELSEIF instead

Check warning on line 39 in includes/Fields/Form_Field_Dropdown.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
$field_settings['options'] = $this->get_posts( 'tribe_organizer' );
}
}
Expand Down
3 changes: 2 additions & 1 deletion includes/Fields/Form_Field_Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,29 @@
public function render( $field_settings, $form_id, $type = 'post', $post_id = null ) {
$selected = isset( $field_settings['selected'] ) ? $field_settings['selected'] : '';

if ( isset( $post_id ) && $post_id != '0' ) {

Check failure on line 29 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Expected exactly one space before closing parenthesis; " " found.

Check warning on line 29 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "!=="; Found: "!="
if ( $this->is_meta( $field_settings ) ) {
$selected = $this->get_meta( $post_id, $field_settings['name'], $type );
}
}
// else {

// $selected = isset( $field_settings['selected'] ) ? $field_settings['selected'] : '';

Check warning on line 36 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 65% valid code; is this commented out code?
// }

$this->field_print_label( $field_settings, $form_id );

do_action( 'WPUF_radio_field_after_label', $field_settings ); ?>
do_action( 'wpuf_radio_field_after_label', $field_settings ); ?>

<div class="wpuf-fields">

<?php
if ( $field_settings['options'] && count( $field_settings['options'] ) > 0 ) {
foreach ( $field_settings['options'] as $value => $option ) {
$selected = is_array( $selected ) ? '' : $selected;
?>

<label <?php echo $field_settings['inline'] == 'yes' ? 'class="wpuf-radio-inline"' : 'class="wpuf-radio-block"'; ?>>

Check warning on line 51 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
<input
name="<?php echo esc_attr( $field_settings['name'] ); ?>"
class="<?php echo esc_attr( 'wpuf_' . $field_settings['name'] . '_' . $form_id ); ?>"
Expand All @@ -61,13 +62,13 @@
</label>
<?php
}
} ?>

Check failure on line 65 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Closing PHP tag must be on a line by itself

<?php $this->help_text( $field_settings ); ?>

</div>

<?php $this->after_field_print_label();

Check failure on line 71 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Opening PHP tag must be on a line by itself
}

/**
Expand Down Expand Up @@ -106,7 +107,7 @@
public function get_field_props() {
$defaults = $this->default_attributes();

$props = [

Check warning on line 110 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Equals sign not aligned correctly; expected 1 space but found 4 spaces
'input_type' => 'radio',
'selected' => '',
'inline' => 'no',
Expand All @@ -131,9 +132,9 @@
public function prepare_entry( $field ) {
check_ajax_referer( 'wpuf_form_add' );

$val = isset( $_POST[$field['name']] ) ? sanitize_text_field( wp_unslash( $_POST[$field['name']] ) ) : '';

Check warning on line 135 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Equals sign not aligned correctly; expected 1 space but found 3 spaces

Check failure on line 135 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Array keys must be surrounded by spaces unless they contain a string or an integer.

Check failure on line 135 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Array keys must be surrounded by spaces unless they contain a string or an integer.

return isset( $field['options'][$val] ) ? $field['options'][$val] : '';

Check failure on line 137 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Array keys must be surrounded by spaces unless they contain a string or an integer.

Check failure on line 137 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Array keys must be surrounded by spaces unless they contain a string or an integer.
}

/**
Expand All @@ -160,8 +161,8 @@

ob_start();
?>
<li class="<?php echo esc_attr( implode( ' ' , $container_classnames ) ); ?>">

Check failure on line 164 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Expected 1 space before closing PHP tag; 2 found

Check failure on line 164 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Space found before comma in argument list
<?php if ( ! $hide_label ): ?>

Check failure on line 165 in includes/Fields/Form_Field_Radio.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Expected 1 space after closing parenthesis; found 0
<label><?php echo esc_html( $field['label'] ); ?>:</label>
<?php endif; ?>
<?php echo esc_html( $field['options'][ $data ] ); ?>
Expand Down
10 changes: 10 additions & 0 deletions includes/Traits/FieldableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ public function update_post_meta( $meta_vars, $post_id ) {
[ $meta_key_value, $multi_repeated, $files ] = self::prepare_meta_fields( $meta_vars );
// set featured image if there's any

/**
* Fires before updating post meta fields
*
* @param int $post_id
* @param array $meta_key_value
* @param array $multi_repeated
* @param array $files
*/
do_action( 'wpuf_before_updating_post_meta_fields', $post_id, $meta_key_value, $multi_repeated, $files );

// @codingStandardsIgnoreStart
$wpuf_files = isset( $_POST['wpuf_files'] ) ? $_POST['wpuf_files'] : [];

Expand Down
Loading