Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/forminator/addons/pro/hubspot/class-forminator-addon-hubspot-quiz-hooks.php
+++ b/forminator/addons/pro/hubspot/class-forminator-addon-hubspot-quiz-hooks.php
@@ -176,12 +176,15 @@
}
$from_object_id = null;
if ( '1' === $create_ticket ) {
+ // Older connections may contain '{{quiz_name}}'.
+ $quiz_name_tags = array( '{{quiz_name}}', '{quiz_name}' );
+ $quiz_name = forminator_get_name_from_model( $this->module );
$ticket['pipeline_id'] = $connection_settings['pipeline_id'];
$ticket['status_id'] = $connection_settings['status_id'];
- $ticket_name = str_ireplace( '{quiz_name}', forminator_get_name_from_model( $this->module ), $connection_settings['ticket_name'] );
+ $ticket_name = str_ireplace( $quiz_name_tags, $quiz_name, $connection_settings['ticket_name'] );
$ticket_name = forminator_addon_replace_custom_vars( $ticket_name, $submitted_data, $this->lead_model, $lead_entry_fields, false );
$ticket['ticket_name'] = $ticket_name;
- $ticket_description = str_ireplace( '{quiz_name}', forminator_get_name_from_model( $this->module ), $connection_settings['ticket_description'] );
+ $ticket_description = str_ireplace( $quiz_name_tags, $quiz_name, $connection_settings['ticket_description'] );
$ticket_description = forminator_addon_replace_custom_vars( $ticket_description, $submitted_data, $this->lead_model, $lead_entry_fields, false );
$ticket['ticket_description'] = $ticket_description;
$ticket['supported_file'] = isset( $submitted_data[ $connection_settings['supported_file'] ] ) ? $submitted_data[ $connection_settings['supported_file'] ] : '';
--- a/forminator/addons/pro/hubspot/class-forminator-addon-hubspot-settings-trait.php
+++ b/forminator/addons/pro/hubspot/class-forminator-addon-hubspot-settings-trait.php
@@ -276,7 +276,7 @@
if ( 'quiz' === static::$module_slug ) {
$fields = array_merge(
array(
- '{quiz_name}' => __( 'Quiz Name', 'forminator' ),
+ 'quiz_name' => __( 'Quiz Name', 'forminator' ),
),
$fields
);
--- a/forminator/admin/abstracts/class-admin-page.php
+++ b/forminator/admin/abstracts/class-admin-page.php
@@ -189,6 +189,7 @@
public function add_page_hooks() {
$page_action = filter_input( INPUT_GET, 'page_action' );
if ( ! forminator_cloud_templates_disabled() && 'hub_connection' === $page_action
+ && Forminator_Hub_Connector::can_manage_hub_connector()
&& ! Forminator_Hub_Connector::hub_connector_connected() ) {
return;
}
@@ -354,9 +355,14 @@
$page_action = filter_input( INPUT_GET, 'page_action' );
$hub_connecting = ! forminator_cloud_templates_disabled() && 'hub_connection' === $page_action;
- if ( $hub_connecting && ! Forminator_Hub_Connector::hub_connector_connected() ) {
+ $can_manage_hub = Forminator_Hub_Connector::can_manage_hub_connector();
+ if ( $hub_connecting && ! Forminator_Hub_Connector::hub_connector_connected()
+ && $can_manage_hub ) {
do_action( 'wpmudev_hub_connector_ui', 'forminator' );
} else {
+ if ( $hub_connecting && ! Forminator_Hub_Connector::hub_connector_connected() && ! $can_manage_hub ) {
+ $this->show_hub_connector_error();
+ }
if ( ! $this->is_edit_page() ) {
$this->render_header();
}
@@ -378,6 +384,24 @@
<?php
}
+ /**
+ * Show error if user does not have permission to connect site to hub
+ */
+ private function show_hub_connector_error() {
+ ?>
+ <div class="sui-notice sui-notice-error" style="margin-bottom: 10px;">
+ <div class="sui-notice-content">
+ <div class="sui-notice-message">
+ <span class="sui-notice-icon sui-md sui-icon-info" aria-hidden="true"></span>
+ <p>
+ <?php esc_html_e( 'You do not have permission to connect this site.', 'forminator' ); ?>
+ </p>
+ </div>
+ </div>
+ </div>
+ <?php
+ }
+
/**
* Show modal when hub connected successfully
*/
--- a/forminator/constants.php
+++ b/forminator/constants.php
@@ -11,7 +11,7 @@
*/
if ( ! defined( 'FORMINATOR_VERSION' ) ) {
- define( 'FORMINATOR_VERSION', '1.58.3' );
+ define( 'FORMINATOR_VERSION', '1.58.4' );
}
if ( ! defined( 'FORMINATOR_SUI_VERSION' ) ) {
--- a/forminator/forminator.php
+++ b/forminator/forminator.php
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: Forminator
- * Version: 1.58.3
+ * Version: 1.58.4
* Plugin URI: https://wpmudev.com/project/forminator/
* Description: Build powerful, customizable forms with ease using Forminator’s drag-and-drop builder, conditional logic, payment support, real-time analytics, and seamless integrations—no coding needed.
* Author: WPMU DEV
--- a/forminator/library/abstracts/abstract-class-front-action.php
+++ b/forminator/library/abstracts/abstract-class-front-action.php
@@ -752,11 +752,17 @@
return $current_entry_fields;
}
+ // If entry fields are empty, use the field data array from the info property.
+ // So that the connected addons can add their fields.
+ $entry_fields = $current_entry_fields;
+ if ( empty( $entry_fields ) && ! empty( self::$info['field_data_array'] ) ) {
+ $entry_fields = self::$info['field_data_array'];
+ }
+
$additional_fields_data = array();
- $submitted_data = static::get_prepared_submitted_data_for_addons( $current_entry_fields );
+ $submitted_data = static::get_prepared_submitted_data_for_addons( $entry_fields );
$connected_addons = forminator_get_addons_instance_connected_with_module( static::$module_id, static::$module_slug );
-
foreach ( $connected_addons as $connected_addon ) {
if ( ! self::are_integration_conditions_matched( $connected_addon ) ) {
continue;
@@ -766,7 +772,7 @@
$hooks = $connected_addon->get_addon_hooks( static::$module_id, static::$module_slug );
}
if ( isset( $hooks ) && $hooks instanceof Forminator_Integration_Hooks ) {
- $addon_fields = $hooks->add_entry_fields( $submitted_data, $current_entry_fields, $entry );
+ $addon_fields = $hooks->add_entry_fields( $submitted_data, $entry_fields, $entry );
// reformat additional fields.
$addon_fields = self::format_addon_additional_fields( $connected_addon, $addon_fields );
$additional_fields_data = array_merge( $additional_fields_data, $addon_fields );
--- a/forminator/library/class-form-fields.php
+++ b/forminator/library/class-form-fields.php
@@ -148,6 +148,7 @@
public function cron_init() {
$this->schedule_delete_temp_files();
$this->cleanup_stripe_checkout_sessions();
+ $this->cleanup_paypal_orders();
// Check if the Stripe webhook is valid and update the option accordingly.
Forminator_Gateway_Stripe::has_valid_webhook();
}
@@ -167,6 +168,21 @@
}
}
+ /**
+ * Cleanup bindings of PayPal orders that were never submitted.
+ *
+ * @since 1.58.4
+ *
+ * @return void
+ */
+ public function cleanup_paypal_orders() {
+ $paypal_field = Forminator_Core::get_field_object( 'paypal' );
+
+ if ( is_object( $paypal_field ) && method_exists( $paypal_field, 'cleanup_order_bindings' ) ) {
+ $paypal_field->cleanup_order_bindings();
+ }
+ }
+
/**
* Schedule delete temp file
*
--- a/forminator/library/class-forminator-hub-connector.php
+++ b/forminator/library/class-forminator-hub-connector.php
@@ -337,4 +337,16 @@
public static function get_hub_connect_logo(): string {
return apply_filters( 'forminator_hub_connect_logo', 'forminator-templates' );
}
+
+ /**
+ * Check if current user can manage hub connector
+ *
+ * @return bool
+ */
+ public static function can_manage_hub_connector(): bool {
+ if ( is_multisite() ? current_user_can( 'manage_network_options' ) : current_user_can( 'manage_options' ) ) {
+ return true;
+ }
+ return false;
+ }
}
--- a/forminator/library/fields/hidden.php
+++ b/forminator/library/fields/hidden.php
@@ -127,7 +127,16 @@
$class_attr = sprintf( ' class="%s"', esc_attr( $custom_class ) );
}
- return sprintf( '<input type="hidden" id="%s"%s name="%s" value="%s" />', esc_attr( $id . '_' . Forminator_CForm_Front::$uid ), $class_attr, esc_attr( $name ), $value );
+ $default_value = self::get_property( 'default_value', $field );
+ // Allow only 'custom_value' and 'query' to be calculable.
+ $is_calculable = ! empty( $default_value ) && in_array( $default_value, array( 'custom_value', 'query' ), true );
+
+ $calculable_attr = '';
+ if ( $is_calculable ) {
+ $calculable_attr = ' data-has-calculation="true"';
+ }
+
+ return sprintf( '<input type="hidden" id="%s"%s%s name="%s" value="%s" />', esc_attr( $id . '_' . Forminator_CForm_Front::$uid ), $class_attr, $calculable_attr, esc_attr( $name ), $value );
}
/**
@@ -209,7 +218,19 @@
* @return string
*/
public static function get_calculable_value( $submitted_field_data, $field_settings ) {
- $calculable_value = $submitted_field_data;
+ $default_value = self::get_property( 'default_value', $field_settings );
+ // Allow only 'custom_value' and 'query' to be calculable.
+ $calculable_value = 0;
+ if ( 'custom_value' === $default_value ) {
+ $custom_value = self::get_property( 'custom_value', $field_settings );
+ if ( ! empty( $custom_value ) && is_numeric( $custom_value ) ) {
+ $calculable_value = floatval( $custom_value );
+ }
+ } elseif ( 'query' === $default_value
+ && ! empty( $submitted_field_data ) && is_numeric( $submitted_field_data ) ) {
+ $calculable_value = floatval( $submitted_field_data );
+ }
+
/**
* Filter formula being used on calculable value on hidden field
*
--- a/forminator/library/fields/paypal.php
+++ b/forminator/library/fields/paypal.php
@@ -17,6 +17,27 @@
class Forminator_PayPal extends Forminator_Field {
/**
+ * Option prefix of an order binding.
+ *
+ * @since 1.58.4
+ */
+ public const ORDER_OPTION_PREFIX = 'forminator_paypal_order_';
+
+ /**
+ * Option key listing order bindings for cleanup.
+ *
+ * @since 1.58.4
+ */
+ public const ORDER_CLEANUP_OPTION_KEY = 'forminator_paypal_order_cleanup';
+
+ /**
+ * Currencies PayPal takes without decimals.
+ *
+ * @since 1.58.4
+ */
+ public const ZERO_DECIMAL_CURRENCIES = array( 'HUF', 'JPY', 'TWD' );
+
+ /**
* Name
*
* @var string
@@ -294,7 +315,13 @@
$entry_data['currency'] = $currency;
$charge_amount = $this->get_payment_amount( $field );
$charge_amount = number_format( $charge_amount, 2, '.', '' );
- $transaction_id = Forminator_CForm_Front_Action::$prepared_data['payment_transaction_id'];
+ $transaction_id = Forminator_CForm_Front_Action::$prepared_data['payment_transaction_id'] ?? '';
+
+ // Accept only an order created for this form, browser and total.
+ $binding_error = self::get_order_binding_error( $transaction_id, $mode, $charge_amount, $currency );
+ if ( '' !== $binding_error ) {
+ return self::get_binding_error_entry_data( $binding_error, $transaction_id, $mode );
+ }
$paypal = new Forminator_PayPal_Express();
$order = $paypal->get_order( $transaction_id, $mode );
@@ -334,7 +361,7 @@
}
// Validate amount.
- if ( ! isset( $order->purchase_units[0]->amount->value ) || floatval( $order->purchase_units[0]->amount->value ) !== floatval( $charge_amount ) ) {
+ if ( ! isset( $order->purchase_units[0]->amount->value ) || self::format_amount( $charge_amount, $currency ) !== (string) $order->purchase_units[0]->amount->value ) {
forminator_maybe_log(
__METHOD__,
array(
@@ -369,6 +396,11 @@
);
}
+ // Claim after PayPal confirmed the order, so a failed lookup can be retried.
+ if ( ! self::claim_order_binding( $transaction_id ) ) {
+ return self::get_binding_error_entry_data( 'already_claimed', $transaction_id, $mode );
+ }
+
$entry_data['amount'] = $charge_amount;
$entry_data['status'] = $order->status;
$entry_data['transaction_id'] = $transaction_id;
@@ -393,6 +425,247 @@
}
/**
+ * Format an amount the way it is sent to PayPal.
+ *
+ * @since 1.58.4
+ *
+ * @param mixed $amount Amount.
+ * @param string $currency Currency code.
+ * @return string
+ */
+ public static function format_amount( $amount, $currency ): string {
+ $decimals = in_array( strtoupper( (string) $currency ), self::ZERO_DECIMAL_CURRENCIES, true ) ? 0 : 2;
+
+ return number_format( (float) $amount, $decimals, '.', '' );
+ }
+
+ /**
+ * Check a PayPal order ID before it is used in an API path.
+ *
+ * @since 1.58.4
+ *
+ * @param mixed $order_id Order ID.
+ * @return bool
+ */
+ private static function is_valid_order_id( $order_id ): bool {
+ return is_string( $order_id ) && 1 === preg_match( '/^[A-Za-z0-9-]{1,64}$/', $order_id );
+ }
+
+ /**
+ * Store what an order was created for.
+ *
+ * @since 1.58.4
+ *
+ * @param string $order_id Order ID.
+ * @param string $form_id Form ID.
+ * @param string $mode Payment mode.
+ * @param mixed $amount Amount.
+ * @param string $currency Currency code.
+ * @return bool
+ */
+ public static function store_order_binding( $order_id, $form_id, $mode, $amount, $currency ): bool {
+ if ( ! self::is_valid_order_id( $order_id ) ) {
+ return false;
+ }
+
+ update_option(
+ self::get_order_option_key( $order_id ),
+ array(
+ 'form_id' => (string) $form_id,
+ 'mode' => 'live' === $mode ? 'live' : 'sandbox',
+ 'amount' => self::format_amount( $amount, $currency ),
+ 'currency' => strtoupper( (string) $currency ),
+ // Reuses the Stripe browser token.
+ 'owner' => Forminator_Stripe::get_payment_owner( true ),
+ 'created_at' => time(),
+ ),
+ false
+ );
+
+ $orders = get_option( self::ORDER_CLEANUP_OPTION_KEY, array() );
+ $orders = is_array( $orders ) ? $orders : array();
+ $orders[ $order_id ] = time();
+ update_option( self::ORDER_CLEANUP_OPTION_KEY, $orders, false );
+
+ return true;
+ }
+
+ /**
+ * Check that an order was created for this form, browser and total.
+ *
+ * @since 1.58.4
+ *
+ * @param mixed $order_id Order ID.
+ * @param string $mode Payment mode.
+ * @param mixed $amount Expected amount.
+ * @param string $currency Expected currency code.
+ * @return string Empty when the order matches, the reason otherwise.
+ */
+ private static function get_order_binding_error( $order_id, $mode, $amount, $currency ): string {
+ if ( ! self::is_valid_order_id( $order_id ) ) {
+ return 'invalid_order_id';
+ }
+
+ $binding = get_option( self::get_order_option_key( $order_id ), false );
+ if ( ! is_array( $binding ) ) {
+ return 'unknown_order';
+ }
+
+ if ( ! Forminator_Stripe::is_payment_owner( $binding['owner'] ?? '' ) ) {
+ return 'owner_mismatch';
+ }
+
+ $form_id = ! empty( Forminator_Front_Action::$module_object->id ) ? (string) Forminator_Front_Action::$module_object->id : '';
+ if (
+ ( $binding['form_id'] ?? '' ) !== $form_id
+ || ( 'live' === $mode ? 'live' : 'sandbox' ) !== ( $binding['mode'] ?? '' )
+ || self::format_amount( $amount, $currency ) !== ( $binding['amount'] ?? '' )
+ || strtoupper( (string) $currency ) !== ( $binding['currency'] ?? '' )
+ ) {
+ return 'binding_mismatch';
+ }
+
+ return '';
+ }
+
+ /**
+ * Claim an order once, only the request that deletes the option succeeds.
+ *
+ * @since 1.58.4
+ *
+ * @param string $order_id Order ID, checked by get_order_binding_error().
+ * @return bool
+ */
+ private static function claim_order_binding( $order_id ): bool {
+ if ( ! delete_option( self::get_order_option_key( $order_id ) ) ) {
+ return false;
+ }
+
+ self::remove_order_from_cleanup( $order_id );
+
+ return true;
+ }
+
+ /**
+ * Log a rejected order and return the entry data error.
+ *
+ * @since 1.58.4
+ *
+ * @param string $reason Reason code.
+ * @param mixed $order_id Order ID.
+ * @param string $mode Payment mode.
+ * @return array
+ */
+ private static function get_binding_error_entry_data( $reason, $order_id, $mode ): array {
+ forminator_maybe_log(
+ __METHOD__,
+ array(
+ 'validation' => 'binding',
+ 'reason' => $reason,
+ 'transaction_id' => $order_id,
+ 'mode' => $mode,
+ )
+ );
+
+ return array(
+ 'error' => esc_html__( 'Error! Something went wrong during checkout and payment couldn't be approved.', 'forminator' ),
+ );
+ }
+
+ /**
+ * Remove an order from the cleanup list.
+ *
+ * @since 1.58.4
+ *
+ * @param string $order_id Order ID.
+ * @return void
+ */
+ private static function remove_order_from_cleanup( $order_id ) {
+ $orders = get_option( self::ORDER_CLEANUP_OPTION_KEY, array() );
+ if ( is_array( $orders ) && isset( $orders[ $order_id ] ) ) {
+ unset( $orders[ $order_id ] );
+ update_option( self::ORDER_CLEANUP_OPTION_KEY, $orders, false );
+ }
+ }
+
+ /**
+ * Delete bindings of orders that were never submitted.
+ *
+ * @since 1.58.4
+ *
+ * @return void
+ */
+ public function cleanup_order_bindings() {
+ $orders = get_option( self::ORDER_CLEANUP_OPTION_KEY, array() );
+ if ( ! is_array( $orders ) || empty( $orders ) ) {
+ return;
+ }
+
+ $expired_before = time() - DAY_IN_SECONDS;
+ foreach ( $orders as $order_id => $created_at ) {
+ if ( (int) $created_at < $expired_before ) {
+ delete_option( self::get_order_option_key( (string) $order_id ) );
+ unset( $orders[ $order_id ] );
+ }
+ }
+
+ update_option( self::ORDER_CLEANUP_OPTION_KEY, $orders, false );
+ }
+
+ /**
+ * Build the option key of an order binding.
+ *
+ * @since 1.58.4
+ *
+ * @param string $order_id Order ID.
+ * @return string
+ */
+ private static function get_order_option_key( $order_id ): string {
+ return self::ORDER_OPTION_PREFIX . md5( (string) $order_id );
+ }
+
+ /**
+ * Get the capture if it completed for the expected total.
+ *
+ * Checks the capture itself, an order can be COMPLETED with a pending or declined capture.
+ *
+ * @since 1.58.4
+ *
+ * @param mixed $response Capture order response.
+ * @param array $field Field.
+ * @return object|WP_Error
+ */
+ public function get_completed_capture( $response, $field ) {
+ // A failed request returns a WP_Error, the caller logs it.
+ if ( is_wp_error( $response ) || ! is_object( $response ) ) {
+ return new WP_Error( 'forminator_paypal_capture_failed', esc_html__( 'Payment failed, please try again!', 'forminator' ) );
+ }
+
+ $currency = self::get_property( 'currency', $field, $this->get_default_currency() );
+ $amount = $this->get_payment_amount( $field );
+ $capture = $response->purchase_units[0]->payments->captures[0] ?? null;
+
+ if ( ! isset( $response->status ) || 'COMPLETED' !== $response->status || ! is_object( $capture ) || empty( $capture->id ) ) {
+ return new WP_Error( 'forminator_paypal_capture_failed', esc_html__( 'Payment failed, please try again!', 'forminator' ) );
+ }
+
+ // The money may still arrive, so don't ask the payer to pay again.
+ if ( 'PENDING' === ( $capture->status ?? '' ) ) {
+ return new WP_Error( 'forminator_paypal_capture_pending', esc_html__( 'Your payment is still being processed by PayPal and couldn't be confirmed. Please contact us before trying again.', 'forminator' ) );
+ }
+
+ if (
+ 'COMPLETED' !== ( $capture->status ?? '' )
+ || (string) ( $capture->amount->value ?? '' ) !== self::format_amount( $amount, $currency )
+ || strtoupper( (string) ( $capture->amount->currency_code ?? '' ) ) !== strtoupper( (string) $currency )
+ ) {
+ return new WP_Error( 'forminator_paypal_capture_failed', esc_html__( 'Payment failed, please try again!', 'forminator' ) );
+ }
+
+ return $capture;
+ }
+
+ /**
* Get transaction link
*
* @param string $mode Payment mode.
--- a/forminator/library/fields/postdata.php
+++ b/forminator/library/fields/postdata.php
@@ -676,6 +676,9 @@
$post_excerpt_label = self::get_property( 'post_excerpt_label', $field, '' );
$post_image_label = self::get_property( 'post_image_label', $field, '' );
+ $image_field_name = $id . '-post-image';
+ $invalid_image = ! empty( $post_image ) && $this->is_invalid_post_image_upload( $image_field_name );
+
if ( $this->is_required( $field ) ) {
if ( empty( $data ) ) {
$postdata_validation_message = apply_filters(
@@ -714,7 +717,7 @@
);
$this->validation_message[ $id . '-post-excerpt' ] = $postdata_post_excerpt_validation_message;
}
- if ( ! empty( $post_image ) && empty( $image ) ) {
+ if ( ! empty( $post_image ) && empty( $image ) && ! $invalid_image ) {
$postdata_post_image_validation_message = apply_filters(
'forminator_postdata_field_post_image_validation_message',
/* Translators: 1. Post image label */
@@ -738,67 +741,108 @@
}
}
}
- } else {
+ } elseif ( ! empty( $data ) && is_array( $data ) ) {
// validation for postdata when its not required.
// `wp_insert_post` required at least ONE OF THESE to be available title / content / excerpt.
// check only when user send some data.
- if ( ! empty( $data ) && is_array( $data ) ) {
- if ( ! $title && ! $content && ! $excerpt ) {
- // check if there is any field with content.
- $is_content_available = false;
- foreach ( $data as $datum ) {
- if ( ! empty( $datum ) ) {
- $is_content_available = true;
- break;
- }
+ if ( ! $title && ! $content && ! $excerpt ) {
+ // check if there is any field with content.
+ $is_content_available = false;
+ foreach ( $data as $datum ) {
+ if ( ! empty( $datum ) ) {
+ $is_content_available = true;
+ break;
}
+ }
- // when $is_content_available false means, field not required, and user didnt put any content on form.
- if ( $is_content_available ) {
- // check if on postdata these sub field is avail available.
- if ( ! empty( $post_title ) ) {
- $this->validation_message[ $id . '-post-title' ] = apply_filters(
- // nr = not required.
- 'forminator_postdata_field_post_title_nr_validation_message',
- $this->get_default_error_message( $field ),
- $id
- );
- }
- if ( ! empty( $post_content ) ) {
- $this->validation_message[ $id . '-post-content' ] = apply_filters(
- // nr = not required.
- 'forminator_postdata_field_post_content_nr_validation_message',
- $this->get_default_error_message( $field ),
- $id
- );
- }
- if ( ! empty( $post_excerpt ) ) {
- $this->validation_message[ $id . '-post-excerpt' ] = apply_filters(
- // nr = not required.
- 'forminator_postdata_field_post_excerpt_nr_validation_message',
- $this->get_default_error_message( $field ),
- $id
- );
- }
+ // when $is_content_available false means, field not required, and user didnt put any content on form.
+ if ( $is_content_available ) {
+ // check if on postdata these sub field is avail available.
+ if ( ! empty( $post_title ) ) {
+ $this->validation_message[ $id . '-post-title' ] = apply_filters(
+ // nr = not required.
+ 'forminator_postdata_field_post_title_nr_validation_message',
+ $this->get_default_error_message( $field ),
+ $id
+ );
}
- }
- }
- $image_field_name = $id . '-post-image';
- if ( ! empty( $post_image ) && isset( $_FILES[ $image_field_name ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- if ( isset( $_FILES[ $image_field_name ]['name'] ) && ! empty( $_FILES[ $image_field_name ]['name'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $file_name = sanitize_file_name( $_FILES[ $image_field_name ]['name'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $valid = wp_check_filetype( $file_name );
-
- if ( false === $valid['ext'] || ! in_array( $valid['ext'], $this->image_extensions, true ) ) {
- $this->validation_message[ $image_field_name ] = apply_filters(
- 'forminator_postdata_field_post_image_nr_validation_message',
- esc_html__( 'Uploaded file's extension is not allowed.', 'forminator' ),
+ if ( ! empty( $post_content ) ) {
+ $this->validation_message[ $id . '-post-content' ] = apply_filters(
+ // nr = not required.
+ 'forminator_postdata_field_post_content_nr_validation_message',
+ $this->get_default_error_message( $field ),
+ $id
+ );
+ }
+ if ( ! empty( $post_excerpt ) ) {
+ $this->validation_message[ $id . '-post-excerpt' ] = apply_filters(
+ // nr = not required.
+ 'forminator_postdata_field_post_excerpt_nr_validation_message',
+ $this->get_default_error_message( $field ),
$id
);
}
}
}
}
+
+ if ( $invalid_image ) {
+ $this->validation_message[ $image_field_name ] = apply_filters(
+ 'forminator_postdata_field_post_image_nr_validation_message',
+ esc_html__( 'Uploaded file's extension is not allowed.', 'forminator' ),
+ $id
+ );
+ }
+ }
+
+ /**
+ * Whether the featured-image input has a file that fails the type check.
+ *
+ * @param string $field_name File input name.
+ * @return bool
+ */
+ private function is_invalid_post_image_upload( $field_name ) {
+ if ( empty( $_FILES[ $field_name ]['name'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ return false;
+ }
+
+ $file_name = sanitize_file_name( wp_unslash( $_FILES[ $field_name ]['name'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ $tmp_name = isset( $_FILES[ $field_name ]['tmp_name'] ) ? wp_unslash( $_FILES[ $field_name ]['tmp_name'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+
+ return false === $this->get_allowed_post_image_filetype( $file_name, $tmp_name );
+ }
+
+ /**
+ * Map an uploaded featured image to an allowed extension and MIME type.
+ *
+ * Uses wp_check_filetype_and_ext() so the file contents have to match the name.
+ *
+ * @param string $file_name Sanitized file name.
+ * @param mixed $tmp_name Uploaded temporary path.
+ * @return array|false Ext and type, or false when the upload is not an allowed image.
+ */
+ private function get_allowed_post_image_filetype( $file_name, $tmp_name ) {
+ if ( ! is_string( $tmp_name ) || '' === $tmp_name || ! is_uploaded_file( $tmp_name ) ) {
+ return false;
+ }
+
+ if ( ! function_exists( 'wp_check_filetype_and_ext' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/file.php';
+ }
+
+ $filetype = wp_check_filetype_and_ext( $tmp_name, $file_name );
+ $image_exts = apply_filters( 'forminator_field_postdata_image_file_types', $this->image_extensions );
+ $ext = isset( $filetype['ext'] ) ? (string) $filetype['ext'] : '';
+ $type = isset( $filetype['type'] ) ? (string) $filetype['type'] : '';
+
+ if ( '' === $ext || '' === $type || ! in_array( $ext, $image_exts, true ) ) {
+ return false;
+ }
+
+ return array(
+ 'ext' => $ext,
+ 'type' => $type,
+ );
}
/**
@@ -855,7 +899,17 @@
return true;
}
if ( ! empty( $_FILES[ $field_name ]['name'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $file_name = sanitize_file_name( $_FILES[ $field_name ]['name'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ $file_name = sanitize_file_name( wp_unslash( $_FILES[ $field_name ]['name'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ $tmp_name = isset( $_FILES[ $field_name ]['tmp_name'] ) ? wp_unslash( $_FILES[ $field_name ]['tmp_name'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+
+ // Check contents before the file is written. This runs before field validation.
+ $wp_filetype = $this->get_allowed_post_image_filetype( $file_name, $tmp_name );
+ if ( false === $wp_filetype ) {
+ return array(
+ 'attachment_id' => 0,
+ 'uploaded_file' => 0,
+ );
+ }
if ( ! function_exists( 'wp_filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
@@ -870,7 +924,7 @@
);
}
- $file_data = $wp_filesystem->get_contents( $_FILES[ $field_name ]['tmp_name'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput
+ $file_data = $wp_filesystem->get_contents( $tmp_name );
$upload_dir = wp_upload_dir(); // Set upload folder.
$unique_file_name = wp_unique_filename( $upload_dir['path'], $file_name );
@@ -882,32 +936,26 @@
$file = $upload_dir['basedir'] . '/' . $filename;
}
- // Check image file type.
- $wp_filetype = wp_check_filetype( $filename, null );
- $image_exts = apply_filters( 'forminator_field_postdata_image_file_types', $this->image_extensions );
- if ( in_array( (string) $wp_filetype['ext'], $image_exts, true ) ) {
-
- // Create the file on the server.
- if ( $wp_filesystem->put_contents( $file, $file_data, FS_CHMOD_FILE ) ) {
- // Set attachment data.
- $attachment = array(
- 'post_mime_type' => $wp_filetype['type'],
- 'post_title' => sanitize_file_name( $filename ),
- 'post_content' => '',
- 'post_status' => 'inherit',
- );
+ // Create the file on the server.
+ if ( $wp_filesystem->put_contents( $file, $file_data, FS_CHMOD_FILE ) ) {
+ // Set attachment data.
+ $attachment = array(
+ 'post_mime_type' => $wp_filetype['type'],
+ 'post_title' => sanitize_file_name( $filename ),
+ 'post_content' => '',
+ 'post_status' => 'inherit',
+ );
- // Create the attachment.
- $attachment_id = wp_insert_attachment( $attachment, $file );
- self::generate_upload_metadata( $attachment_id, $file );
-
- $uploaded_file = wp_get_attachment_image_src( $attachment_id, 'large', false );
- if ( $uploaded_file && is_array( $uploaded_file ) ) {
- return array(
- 'attachment_id' => $attachment_id,
- 'uploaded_file' => $uploaded_file,
- );
- }
+ // Create the attachment.
+ $attachment_id = wp_insert_attachment( $attachment, $file );
+ self::generate_upload_metadata( $attachment_id, $file );
+
+ $uploaded_file = wp_get_attachment_image_src( $attachment_id, 'large', false );
+ if ( $uploaded_file && is_array( $uploaded_file ) ) {
+ return array(
+ 'attachment_id' => $attachment_id,
+ 'uploaded_file' => $uploaded_file,
+ );
}
}
}
@@ -955,6 +1003,7 @@
$image = isset( $data['post-image'] ) ? $data['post-image'] : '';
$post_meta = isset( $data['post-custom'] ) ? $data['post-custom'] : '';
+ // Shortcodes are neutralized in sanitize().
$post = array(
'post_author' => $post_author,
'post_content' => wp_kses_post( $content ),
@@ -1156,10 +1205,42 @@
$data['post-content'] = $content;
}
+ $post_type = self::get_property( 'post_type', $field, 'post' );
+ foreach ( array( 'post-title', 'post-content', 'post-excerpt' ) as $key ) {
+ if ( isset( $data[ $key ] ) ) {
+ $data[ $key ] = $this->neutralize_shortcodes( $data[ $key ], $post_type );
+ }
+ }
+
return apply_filters( 'forminator_field_postdata_sanitize', $data, $field, $original_data );
}
/**
+ * Encode shortcode brackets unless the submitter can edit posts of this type.
+ * Safer than strip_shortcodes(), which turns [[tag]] into a live [tag].
+ *
+ * @since 1.58.4
+ *
+ * @param string $text Submitted text.
+ * @param string $post_type Post type the field creates.
+ *
+ * @return string
+ */
+ private function neutralize_shortcodes( $text, $post_type ) {
+ if ( ! is_string( $text ) || false === strpbrk( $text, '[]' ) ) {
+ return $text;
+ }
+
+ $post_type_object = get_post_type_object( $post_type );
+ $edit_cap = $post_type_object ? $post_type_object->cap->edit_posts : 'edit_posts';
+ if ( current_user_can( $edit_cap ) ) {
+ return $text;
+ }
+
+ return str_replace( array( '[', ']' ), array( '[', ']' ), $text );
+ }
+
+ /**
* Return field inline validation rules
* Workaround for actually input file is hidden, so its not accessible via standar html5 `required` attribute
*
--- a/forminator/library/fields/stripe.php
+++ b/forminator/library/fields/stripe.php
@@ -3861,6 +3861,25 @@
}
/**
+ * Whether a Checkout Session has finished Checkout and may receive the after-payment response.
+ *
+ * The payment-owner cookie only proves which browser started the session. An open/unpaid
+ * session must not disclose thank-you messages, redirect URLs, or other gated content.
+ * Status complete covers paid, no_payment_required, and async unpaid (ACH/SEPA) after the
+ * customer finishes Checkout.
+ *
+ * @since 1.58.4
+ *
+ * @param mixed $session Checkout Session object.
+ * @return bool
+ */
+ public static function is_checkout_session_completed( $session ): bool {
+ return is_object( $session )
+ && ! empty( $session->status )
+ && 'complete' === $session->status;
+ }
+
+ /**
* Determine whether a Checkout Session can still be recovered for retry.
*
* @since 1.56
--- a/forminator/library/gateways/class-paypal-express.php
+++ b/forminator/library/gateways/class-paypal-express.php
@@ -598,7 +598,13 @@
* @return mixed
*/
public function capture_order( $id, $mode ) {
- return $this->api_request( 'v2/checkout/orders/' . $id . '/capture', $mode, array(), 'POST' );
+ // Return the full capture, its status and amount are verified.
+ $args = array(
+ 'headers' => array( 'Prefer' => 'return=representation' ),
+ 'body' => array(),
+ );
+
+ return $this->api_request( 'v2/checkout/orders/' . $id . '/capture', $mode, $args, 'POST' );
}
/**
--- a/forminator/library/helpers/helper-core.php
+++ b/forminator/library/helpers/helper-core.php
@@ -761,6 +761,32 @@
}
/**
+ * Return if PayPal mode is configured
+ *
+ * @since 1.58.4
+ *
+ * @param string $mode Payment mode (sandbox|live).
+ * @return bool
+ */
+function forminator_is_paypal_mode_ready( $mode ) {
+ if ( class_exists( 'Forminator_PayPal_Express' ) ) {
+ try {
+ $paypal = new Forminator_PayPal_Express();
+
+ if ( 'sandbox' !== $mode ) {
+ $paypal->set_live( true );
+ }
+
+ return $paypal->is_ready();
+ } catch ( Forminator_Gateway_Exception $e ) {
+ return false;
+ }
+ }
+
+ return false;
+}
+
+/**
* Check if the Stripe Subscription add-on is installed and meets Forminator's minimum version.
*
* @since 1.58.0
@@ -1092,7 +1118,7 @@
global $wp;
// Check Pro theme by Themeco https://theme.co/.
- if ( defined( 'X_TEMPLATE_PATH' ) && 'cornerstone-endpoint' === $wp->request ) {
+ if ( defined( 'X_TEMPLATE_PATH' ) && 'cornerstone-endpoint' === $wp->request && current_user_can( 'edit_posts' ) ) {
$decision = true;
return $decision;
}
@@ -1113,7 +1139,7 @@
// Check Elementor plugin.
$action = Forminator_Core::sanitize_text_field( 'action' );
$editor_post_id = (int) Forminator_Core::sanitize_text_field( 'editor_post_id' );
- if ( defined( 'ELEMENTOR_VERSION' ) && 'elementor_ajax' === $action && $editor_post_id ) {
+ if ( defined( 'ELEMENTOR_VERSION' ) && 'elementor_ajax' === $action && $editor_post_id && current_user_can( 'edit_post', $editor_post_id ) ) {
$decision = true;
return $decision;
}
--- a/forminator/library/helpers/helper-fields.php
+++ b/forminator/library/helpers/helper-fields.php
@@ -811,6 +811,10 @@
*/
$value = apply_filters( 'forminator_empty_field_placeholder', $value, $element_id );
}
+ // HTML fields are admin templates and may still need merge tags resolved later.
+ if ( is_string( $value ) && 0 !== strpos( $element_id, 'html' ) ) {
+ $value = forminator_neutralize_merge_tags( $value );
+ }
if ( ! $urlencode ) {
$content = forminator_replace_placeholder_in_urls( $content, $match, $value );
}
@@ -1108,15 +1112,18 @@
* @return mixed
*/
function forminator_replace_custom_form_data( $content, Forminator_Form_Model $custom_form, Forminator_Form_Entry_Model $entry, $excluded = array() ) {
+ // Expand scalar tags before {all_fields} / {all_non_empty_fields}. Otherwise a submitted
+ // value that contains e.g. {account_approval_link} or {submission_url} is copied into the
+ // body by {all_fields} and then resolved by a later pass (second-order merge tag injection).
$custom_form_datas = array(
- '{all_fields}' => 'forminator_get_formatted_form_entry',
- '{all_non_empty_fields}' => 'forminator_get_formatted_form_non_empty_entry',
+ '{account_approval_link}' => 'forminator_get_account_approval_link',
'{form_name}' => 'forminator_get_formatted_form_name',
'{submission_id}' => 'forminator_get_submission_id',
'{submission_url}' => 'forminator_get_submission_url',
- '{account_approval_link}' => 'forminator_get_account_approval_link',
'{username}' => 'forminator_get_formatted_username',
'{line_break}' => 'forminator_get_formatted_line_break',
+ '{all_fields}' => 'forminator_get_formatted_form_entry',
+ '{all_non_empty_fields}' => 'forminator_get_formatted_form_non_empty_entry',
);
foreach ( $custom_form_datas as $custom_form_data => $function ) {
@@ -1136,6 +1143,26 @@
}
/**
+ * Neutralize merge-tag braces in user-supplied values.
+ *
+ * Submitted field values must not be interpreted as Forminator merge tags when they
+ * are inserted into email bodies or other templates (second-order merge tag injection).
+ *
+ * @since 1.58.4
+ *
+ * @param string $text Text that may contain curly braces.
+ *
+ * @return string
+ */
+function forminator_neutralize_merge_tags( $text ) {
+ if ( ! is_string( $text ) || false === strpos( $text, '{' ) ) {
+ return $text;
+ }
+
+ return str_replace( array( '{', '}' ), array( '{', '}' ), $text );
+}
+
+/**
* Replace placeholder occurrences inside URLs with provided value.
*
* @param string $content Original content.
@@ -1361,6 +1388,10 @@
$value = forminator_replace_linebreaks( esc_html( $value ) );
}
}
+ // Submitted values must not reintroduce merge tags into the email body.
+ if ( is_string( $value ) ) {
+ $value = forminator_neutralize_merge_tags( $value );
+ }
$html .= $value . '<br/>';
}
$html .= '</li>';
--- a/forminator/library/model/class-poll-form-model.php
+++ b/forminator/library/model/class-poll-form-model.php
@@ -185,7 +185,8 @@
}
$cookie_value = date_i18n( 'Y-m-d H:i:s', strtotime( sanitize_text_field( wp_unslash( $_COOKIE[ $poll_cookie ] ) ) ) );
$cookie_expire = $cookie_value . ' +' . $duration . ' ' . $interval;
- if ( time() < strtotime( $cookie_expire ) ) {
+ $current_date = date_i18n( 'Y-m-d H:i:s' );
+ if ( strtotime( $current_date ) < strtotime( $cookie_expire ) ) {
return false;
} else {
return true;
--- a/forminator/library/modules/custom-forms/front/front-action.php
+++ b/forminator/library/modules/custom-forms/front/front-action.php
@@ -66,6 +66,13 @@
public static $registration = null;
/**
+ * Login waiting for the payment to be confirmed
+ *
+ * @var Forminator_CForm_Front_User_Login|null
+ */
+ private static $deferred_login = null;
+
+ /**
* Plugin instance
*
* @var null
@@ -157,16 +164,7 @@
* @return array
*/
private static function prepare_pp_price( $amount ) {
- $integer_currencies = array(
- 'HUF',
- 'JPY',
- 'TWD',
- );
- if ( isset( $amount['currency_code'] ) && in_array( $amount['currency_code'], $integer_currencies, true ) ) {
- $amount['value'] = number_format( (float) $amount['value'], 0, '.', '' );
- } else {
- $amount['value'] = number_format( (float) $amount['value'], 2, '.', '' );
- }
+ $amount['value'] = Forminator_PayPal::format_amount( $amount['value'], $amount['currency_code'] ?? '' );
return $amount;
}
@@ -267,7 +265,12 @@
$paypal = new Forminator_PayPal_Express();
$order = $paypal->create_order( $request, $mode );
- if ( is_wp_error( $order ) || empty( $order->id ) ) {
+ // Bind the order to this form, browser and total.
+ if (
+ is_wp_error( $order )
+ || empty( $order->id )
+ || ! Forminator_PayPal::store_order_binding( $order->id, $form_id, $mode, $purchase_unit['amount']['value'], $purchase_unit['amount']['currency_code'] )
+ ) {
wp_send_json_error( esc_html__( 'Cannot create a new order on PayPal. If the error persists, please contact us for further assistance.', 'forminator' ) );
}
@@ -638,24 +641,58 @@
$response = $this->handle_form( false, true );
if ( is_array( $response ) && isset( $response['success'] ) && $response['success'] ) {
- // If the form is a login form, return the full response to the front end to handle the login process.
- if ( isset( self::$module_settings['form-type'] ) && 'login' === self::$module_settings['form-type'] ) {
- wp_send_json_success(
- $response
- );
- } else {
- wp_send_json_success(
- array(
- 'message' => $response['message'],
- 'entry_id' => $response['entry_id'],
- )
- );
- }
+ wp_send_json_success( self::get_pending_checkout_validate_success_response( $response ) );
}
wp_send_json_error( $response );
}
/**
+ * Build the pending Checkout validate success payload.
+ *
+ * Pending validate runs before Checkout finishes, so after-payment Behavior
+ * (thank-you / redirect) must not be returned. Login forms still need the
+ * Defender 2FA fields from the original response.
+ *
+ * @param array $response Full handle_form success response.
+ * @return array
+ */
+ private static function get_pending_checkout_validate_success_response( $response ) {
+ if ( isset( self::$module_settings['form-type'] ) && 'login' === self::$module_settings['form-type'] ) {
+ return self::get_pending_checkout_login_validate_response( $response );
+ }
+
+ return array(
+ 'entry_id' => isset( $response['entry_id'] ) ? $response['entry_id'] : 0,
+ );
+ }
+
+ /**
+ * Keep Defender 2FA fields on pending Checkout validate for login forms.
+ *
+ * Starts from the existing login response and only removes after-payment
+ * Behavior keys. Invalid 2FA still needs its error message.
+ *
+ * @param array $response Full handle_form success response.
+ * @return array
+ */
+ private static function get_pending_checkout_login_validate_response( $response ) {
+ unset(
+ $response['url'],
+ $response['behav'],
+ $response['redirect'],
+ $response['newtab'],
+ $response['fadeout'],
+ $response['fadeout_time']
+ );
+
+ if ( empty( $response['authentication'] ) || 'invalid' !== $response['authentication'] ) {
+ unset( $response['message'] );
+ }
+
+ return $response;
+ }
+
+ /**
* Add a temporary country code based on currency to prevent errors.
* Set country code to Austria if currency is Euro,
* else remove the last letter from currency code to get temporary country code.
@@ -883,7 +920,14 @@
}
$forminator_user_login = new Forminator_CForm_Front_User_Login();
- $login_user = $forminator_user_login->process_login( self::$module_object, $entry, self::$info['field_data_array'] );
+
+ // PayPal is captured later, so only check the credentials now.
+ if ( self::$is_paypal_payment ) {
+ $forminator_user_login->defer_signon();
+ self::$deferred_login = $forminator_user_login;
+ }
+
+ $login_user = $forminator_user_login->process_login( self::$module_object, $entry, self::$info['field_data_array'] );
if ( is_wp_error( $login_user['user'] ) ) {
$messages = $login_user['user']->get_error_messages();
throw new Exception(
@@ -929,6 +973,29 @@
}
/**
+ * Sign on the user whose login waited for the payment.
+ *
+ * The payment is already taken, so a failure is only logged.
+ *
+ * @since 1.58.4
+ *
+ * @return void
+ */
+ private static function complete_deferred_login() {
+ if ( ! self::$deferred_login ) {
+ return;
+ }
+
+ $login = self::$deferred_login;
+ self::$deferred_login = null;
+
+ $user = $login->complete_deferred_signon();
+ if ( is_wp_error( $user ) ) {
+ forminator_maybe_log( __METHOD__, $user->get_error_messages() );
+ }
+ }
+
+ /**
* Handle registration form validation separately
*
* @since 1.17.2
@@ -1520,20 +1587,11 @@
}
throw new Exception( esc_html( $stripe_entry_data['value']->get_error_message() ) );
}
+ if ( ! empty( $stripe_entry_data['value']['error'] ) ) {
+ throw new Exception( esc_html( $stripe_entry_data['value']['error'] ) );
+ }
- /**
- * Fires after charge stripe
- *
- * @since 1.7
- *
- * @param Forminator_Form_Model $module_object
- * @param array $field field properties.
- * @param array $stripe_entry_data
- * @param array $submitted_data
- * @param array $field_data_array
- */
- do_action( 'forminator_custom_form_after_stripe_charge', self::$module_object, $field, $stripe_entry_data, self::$prepared_data, self::$info['field_data_array'] );
-
+ // Not paid yet, the hook fires once the Checkout Session is paid.
if ( $field_object->is_checkout_session( $field ) ) {
return $stripe_entry_data;
}
@@ -1580,6 +1638,20 @@
);
$stripe_entry_data['value'] = array_merge( $stripe_entry_data['value'], $result );
+ /**
+ * Fires after the Stripe payment is confirmed
+ *
+ * @since 1.7
+ * @since 1.58.4 Fires only after the payment succeeded.
+ *
+ * @param Forminator_Form_Model $module_object
+ * @param array $field field properties.
+ * @param array $stripe_entry_data
+ * @param array $submitted_data
+ * @param array $field_data_array
+ */
+ do_action( 'forminator_custom_form_after_stripe_charge', self::$module_object, $field, $stripe_entry_data, self::$prepared_data, self::$info['field_data_array'] );
+
return $stripe_entry_data;
}
@@ -1621,6 +1693,7 @@
*
* @param object $entry Entry.
* @return array|void
+ * @throws Exception When the configured Stripe mode is unavailable.
*/
private static function handle_stripe( $entry ) {
if ( self::$is_draft || self::$is_spam ) {
@@ -1632,8 +1705,12 @@
}
$stripe_mode = isset( self::$info['stripe_field']['mode'] ) ? self::$info['stripe_field']['mode'] : 'test';
+ // Fail closed: unavailable Stripe must not skip payment and continue as a free submit
+ // (e.g. registration with a configured role).
if ( ! forminator_is_stripe_mode_ready( $stripe_mode ) ) {
- return;
+ throw new Exception(
+ esc_html__( 'Payment is currently unavailable. Please try again later.', 'forminator' )
+ );
}
$stripe_field_data = self::stripe_field_to_entry_data_array( $entry );
@@ -1705,6 +1782,14 @@
return;
}
+ $paypal_mode = isset( self::$info['paypal_field']['mode'] ) ? self::$info['paypal_field']['mode'] : 'sandbox';
+ // Fail closed: unavailable PayPal must not skip payment and continue as a free submit.
+ if ( ! forminator_is_paypal_mode_ready( $paypal_mode ) ) {
+ throw new Exception(
+ esc_html__( 'Payment is currently unavailable. Please try again later.', 'forminator' )
+ );
+ }
+
if ( self::$module_object->is_payment_require_ssl() && ! is_ssl() ) {
throw new Exception(
esc_html(
@@ -2074,7 +2159,9 @@
if ( self::$is_leads ) {
// Update the entry status to active.
- $entry->update_status( 'active' );
+ if ( $entry->update_status( 'active' ) ) {
+ self::fire_checkout_after_stripe_charge( $stripe_data );
+ }
// Process integrated add-ons and emails for quizzes.
$form_action = new Forminator_Quiz_Front_Action();
@@ -2120,7 +2207,9 @@
}
// Update the entry status to active.
- $entry->update_status( 'active' );
+ if ( $entry->update_status( 'active' ) ) {
+ self::fire_checkout_after_stripe_charge( $stripe_data );
+ }
// Update hidden fields with submission ID if they exist in the prepared data.
$this->maybe_update_hidden_fields( $entry );
@@ -2169,6 +2258,35 @@
}
/**
+ * Fire the Stripe after charge hook for a paid Checkout Session.
+ *
+ * Fires once, when the entry turns active. Subscriptions are left to the add-on.
+ *
+ * @since 1.58.4
+ *
+ * @param array $stripe_data Stripe entry meta with the final transaction ID.
+ * @return void
+ */
+ private static function fire_checkout_after_stripe_charge( $stripe_data ) {
+ if (
+ ! is_array( $stripe_data )
+ || 'COMPLETED' !== ( $stripe_data['status'] ?? '' )
+ || ! empty( $stripe_data['subscription_id'] )
+ ) {
+ return;
+ }
+
+ $field = self::$info['stripe_field'] ?? array();
+ $stripe_entry_data = array(
+ 'name' => $field['element_id'] ?? '',
+ 'value' => $stripe_data,
+ );
+
+ /** This action is documented in handle_stripe_single(). */
+ do_action( 'forminator_custom_form_after_stripe_charge', self::$module_object, $field, $stripe_entry_data, self::$prepared_data, self::$info['field_data_array'] ?? array() );
+ }
+
+ /**
* Update hidden fields with submission ID if they exist in the prepared data.
*
* @param Forminator_Form_Entry_Model $entry Form Entry.
@@ -2448,6 +2566,11 @@
if ( ! Forminator_Stripe::is_payment_owner( $payment_response['owner'] ?? '' ) ) {
return self::get_foreign_payment_response();
}
+ // Re-check Stripe so a stale unpaid transient cannot disclose gated content.
+ if ( ! $this->pending_checkout_session_allows_after_payment_response( $session_id ) ) {
+ delete_transient( $transient_response_key );
+ return self::get_incomplete_checkout_payment_response();
+ }
// Delete the transient after retrieving the response, as it is no longer needed.
delete_transient( $transient_response_key );
return $payment_response;
@@ -2487,8 +2610,19 @@
// Only process entries of the current form.
if ( $current_form_id === (int) $form_id ) {
- // Apply stored payment description once the PaymentIntent exists (after confirm).
$stripe_settings = $this->get_stripe_field_settings();
+
+ // Owner cookie is not proof of payment. Active entries were already confirmed by
+ // webhook/cron; failed entries keep their error path. Pending ones need a
+ // completed Checkout Session before gated thank-you/redirect content.
+ if (
+ ! in_array( $entry->status, array( 'active', 'failed' ), true )
+ && ! $this->pending_checkout_session_allows_after_payment_response( $session_id, $stripe_settings )
+ ) {
+ return self::get_incomplete_checkout_payment_response();
+ }
+
+ // Apply stored payment description once the PaymentIntent exists (after confirm).
if ( ! empty( $stripe_settings ) ) {
$stripe_field_obj = Forminator_Core::get_field_object( 'stripe' );
if ( $stripe_field_obj instanceof Forminator_Stripe ) {
@@ -2562,6 +2696,50 @@
}
/**
+ * Whether a pending Checkout Session may receive the after-payment response.
+ *
+ * @param string $session_id Checkout Session ID.
+ * @param array|null $stripe_settings Stripe field settings.
+ * @return bool
+ */
+ private function pending_checkout_session_allows_after_payment_response( $session_id, $stripe_settings = null ) {
+ if ( empty( $session_id ) ) {
+ return false;
+ }
+
+ if ( empty( $stripe_settings ) ) {
+ $stripe_settings = $this->get_stripe_field_settings();
+ }
+
+ $stripe_field_obj = Forminator_Core::get_field_object( 'stripe' );
+ if ( ! $stripe_field_obj instanceof Forminator_Stripe || empty( $stripe_settings ) ) {
+ return false;
+ }
+
+ $session = $stripe_field_obj->get_checkout_session_by_id( $session_id, $stripe_settings );
+
+ return Forminator_Stripe::is_checkout_session_completed( $session );
+ }
+
+ /**
+ * Response when Checkout has not finished yet.
+ *
+ * Keeps the pending session so the owner can complete payment and retry.
+ *
+ * @return array
+ */
+ private static function get_incomplete_checkout_payment_response() {
+ self::$submit_errors = array();
+
+ return array(
+ 'return' => true,
+ 'data' => self::return_error(
+ esc_html__( 'Payment is not complete. Please finish payment and try again.', 'forminator' )
+ ),
+ );
+ }
+
+ /**
* Message for a Stripe payment resumed in a browser that did not start it.
*
* @return string
@@ -2651,8 +2829,8 @@
}
self::maybe_login( $entry );
- if ( $is_pending && ! empty( self::$response_attrs['authentication'] ) ) {
- // To handle Defender 2FA, we should not create a pending entry if the user is not authenticated yet.
+ if ( ( $is_pending || self::$is_paypal_payment ) && ! empty( self::$response_attrs['authentication'] ) ) {
+ // To handle Defender 2FA, no pending entry or PayPal payment until the user is authenticated.
if ( in_array( self::$response_attrs['authentication'], array( 'invalid', 'show' ), true ) ) {
return self::return_success();
}
@@ -2685,6 +2863,8 @@
self::handle_paypal( $entry );
unset( $delete_submission );
+ self::complete_deferred_login();
+
self::process_uploads( 'transfer' );
self::save_entry_fields( $entry );
@@ -2917,11 +3097,6 @@
protected static function get_prepared_submitted_data_for_addons( $current_entry_fields ) {
$data = self::get_submitted_data();
- // An empty list only keeps addon rows out of the entry. Format values from the form fields.
- if ( empty( $current_entry_fields ) && ! empty( self::$info['field_data_array'] ) ) {
- $current_entry_fields = self::$info['field_data_array'];
- }
-
foreach ( wp_list_pluck( $current_entry_fields, 'name' ) as $element_id ) {
$data[ $element_id ] = Forminator_Integration_Form_Hooks::prepare_field_value_for_addon( $element_id, $current_entry_fields, $data );
}
@@ -2986,7 +3161,9 @@
// Set the entry ID in the prepared data so that the form fields can be correctly processed for addon.
self::$prepared_data['entry_id'] = $entry->entry_id;
// If the entry is pending, we need to re-prepare the fields info to handle post submission process.
- $fields = self::get_fields();
+ // Reset it first, so fields already prepared from the entry are not processed twice.
+ self::$info['field_data_array'] = array();
+ $fields = self::get_fields();
foreach ( $fields as $field_index => $field ) {
self::set_field_data_array( $field_index, $field );
}
@@ -3708,48 +3885,55 @@
return;
}
forminator_maybe_log( __METHOD__, $paypal_entry_data['value'] );
+ if ( is_wp_error( $paypal_entry_data['value'] ) ) {
+ throw new Exception( esc_html( $paypal_entry_data['value']->get_error_message() ) );
+ }
if ( ! empty( $paypal_entry_data['value']['error'] ) ) {
throw new Exception( esc_html( $paypal_entry_data['value']['error'] ) );
}
- /**
- * Fires after charge paypal
- *
- * @since 1.7
- *
- * @param Forminator_Form_Model $module_object
- * @param array $field field properties.
- * @param array $paypal_entry_data
- * @param array $submitted_data
- * @param array $field_data_array
- */
- do_action( 'forminator_custom_form_after_paypal_charge', self::$module_object, $field, $paypal_entry_data, self::$prepared_data, self::$info['field_data_array'] );
+ // Never capture an order that failed validation.
+ if ( ! empty( $entry_data['error'] ) || empty( $entry_data['transaction_id'] ) ) {
+ throw new Exception( esc_html( ! empty( $entry_data['error'] ) ? $entry_data['error'] : __( 'Payment failed, please try again!', 'forminator' ) ) );
+ }
$paypal = new Forminator_PayPal_Express();
$mode = isset( $field['mode'] ) ? $field['mode'] : 'sandbox';
$capture = $paypal->capture_order( $entry_data['transaction_id'], $mode );
+ $payment = $field_object->get_completed_capture( $capture, $field );
- if ( ! isset( $capture->status ) || 'COMPLETED' !== $capture->status ) {
+ if ( is_wp_error( $payment ) ) {
forminator_maybe_log(
__METHOD__,
array(
'transaction_id' => $entry_data['transaction_id'],
'mode' => $mode,
+ 'error' => $payment->get_error_code(),
'order_status' => isset( $capture->status ) ? $capture->status : '',
'capture_result' => $capture,
)
);
- throw new Exception( esc_html__( 'Payment failed, please try again!', 'forminator' ) );
+ throw new Exception( esc_html( $payment->get_error_message() ) );
}
- $paypal_entry_data['value']['status'] = 'COMPLETED';
- if ( isset( $capture->purchase_units[0]->payments->captures[0]->id ) ) {
- $transaction_id = $capture->purchase_units[0]->payments->captures[0]->id;
+ $paypal_entry_data['value']['status'] = 'COMPLETED';
+ $paypal_entry_data['value']['transaction_id'] = $payment->id;
+ $paypal_entry_data['value']['transaction_link'] = $field_object::get_transanction_link( $mode, $payment->id );
- $paypal_entry_data['value']['transaction_id'] = $transaction_id;
- $paypal_entry_data['value']['transaction_link'] = $field_object::get_transanction_link( $mode, $transaction_id );
- }
+ /**
+ * Fires after the PayPal payment is captured and confirmed
+ *
+ * @since 1.7
+ * @since 1.58.4 Fires only after a completed capture.
+ *
+ * @param Forminator_Form_Model $module_object
+ * @param array $field field properties.
+ * @param array $paypal_entry_data
+ * @param array $submitted_data
+ * @param array $field_data_array
+ */
+ do_action( 'forminator_custom_form_after_paypal_charge', self::$module_object, $field, $paypal_entry_data, self::$prepared_data, self::$info['field_data_array'] );
self::$info['field_data_array'][] = $paypal_entry_data;
}
@@ -4111,7 +4295,8 @@
// skip validation, hidden values = 0 or 1.
$value = self::replace_to( $field_id, $converted_formula );
} else {
- $value = $visible_fields[ $field_id ];
+ // Cast the value to float to ensure that it is a numeric value. This prevents issues with non-numeric values being injected into the formula.
+ $value = floatval( $visible_fields[ $field_id ] );
}
// Replace only the first occurence.
--- a/forminator/library/modules/custom-forms/front/front-user-login.php
+++ b/forminator/library/modules/custom-forms/front/front-user-login.php
@@ -41,6 +41,20 @@
public $settings;
/**
+ * Whether sign on waits for complete_deferred_signon()
+ *
+ * @var bool
+ */
+ private $defer_signon = false;
+
+ /**
+ * Checked credentials waiting for sign on
+ *
+ * @var array
+ */
+ private $deferred_signon = array();
+
+ /**
* Forminator_CForm_Front_User_Login constructor
*/
public function __construct() {
@@ -226,6 +240,14 @@
'value' => $user_fields,
);
}
+ } elseif ( $this->defer_signon ) {
+ // Only check the credentials, sign on follows the payment.
+ if ( empty( $sign_on ) ) {
+ $sign_on = wp_authenticate( $username, $password );
+ }
+ if ( ! is_wp_error( $sign_on ) ) {
+ $this->deferred_signon = $user_fields;
+ }
} else {
$sign_on = wp_signon( $user_fields );
}
@@ -238,6 +260,35 @@
}
/**
+ * Check the credentials in process_login() without signing on.
+ *
+ * @since 1.58.4
+ *
+ * @return void
+ */
+ public function defer_signon() {
+ $this->defer_signon = true;
+ }
+
+ /**
+ * Sign on the user whose credentials passed process_login().
+ *
+ * @since 1.58.4
+ *
+ * @return WP_User|WP_Error|null Null when nothing waits for sign on.
+ */
+ public function complete_deferred_signon() {
+ if ( empty( $this->deferred_signon ) ) {
+ return null;
+ }
+
+ $user_fields = $this->deferred_signon;
+ $this->deferred_signon = array();
+
+ return wp_signon( $user_fields );
+ }
+
+ /**
* Redirect page if form is submitted