From 5f687daec56fbf8c56ae952b9ce51362b00f4d64 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sun, 21 Jul 2024 14:23:55 +0300 Subject: [PATCH] Fix error with the Elementor Checkout Element. --- readme.txt | 1 + src/php/AutoVerify/AutoVerify.php | 8 +------- src/php/GiveWP/Base.php | 9 ++------- src/php/Helpers/Request.php | 25 ++++++++++++++++++++++++- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/readme.txt b/readme.txt index 4a9eb51c..a2360d81 100644 --- a/readme.txt +++ b/readme.txt @@ -565,6 +565,7 @@ Instructions for popular native integrations are below: * Fixed conflict with Ninja Forms Upload field. * Fixed Ninja Forms Ajax processing. * Fixed error in cron with Matomo Analytics. +* Fixed error with the Elementor Checkout Element. = 4.3.1 = * Added a live form in the Contact Form 7 admin form view. diff --git a/src/php/AutoVerify/AutoVerify.php b/src/php/AutoVerify/AutoVerify.php index f3a92a0d..82856e2d 100644 --- a/src/php/AutoVerify/AutoVerify.php +++ b/src/php/AutoVerify/AutoVerify.php @@ -73,13 +73,7 @@ public function widget_block_content_filter( $content, array $instance, WP_Widge * @noinspection ForgottenDebugOutputInspection */ public function verify_form(): void { - if ( ! Request::is_frontend() ) { - return; - } - - $request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_METHOD'] ), FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : ''; - - if ( 'POST' !== $request_method ) { + if ( ! Request::is_post() || ! Request::is_frontend() ) { return; } diff --git a/src/php/GiveWP/Base.php b/src/php/GiveWP/Base.php index c9a40f46..7b78cfe5 100644 --- a/src/php/GiveWP/Base.php +++ b/src/php/GiveWP/Base.php @@ -14,6 +14,7 @@ use Give\DonationForms\ValueObjects\DonationFormErrorTypes; use HCaptcha\Helpers\HCaptcha; +use HCaptcha\Helpers\Request; use WP_Error; /** @@ -128,13 +129,7 @@ public function verify( $valid_data ): void { * @return void */ public function verify_block(): void { - // phpcs:disable WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended - $request_method = isset( $_SERVER['REQUEST_METHOD'] ) - ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) - : ''; - // phpcs:enable WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended - - if ( 'POST' !== $request_method ) { + if ( ! Request::is_post() ) { return; } diff --git a/src/php/Helpers/Request.php b/src/php/Helpers/Request.php index abcae166..4c1115c5 100644 --- a/src/php/Helpers/Request.php +++ b/src/php/Helpers/Request.php @@ -20,7 +20,7 @@ class Request { * @return bool */ public static function is_frontend(): bool { - return ! ( self::is_cli() || is_admin() || wp_doing_ajax() || self::is_rest() ); + return ! ( self::is_cli() || is_admin() || wp_doing_ajax() || self::is_wc_ajax() || self::is_rest() ); } /** @@ -78,4 +78,27 @@ public static function is_rest(): bool { return 0 === strpos( $current_url, $rest_url ); } + + /** + * Check if it is a POST request. + * + * @return bool + */ + public static function is_post(): bool { + $request_method = isset( $_SERVER['REQUEST_METHOD'] ) + ? strtoupper( filter_var( wp_unslash( $_SERVER['REQUEST_METHOD'] ), FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ) + : ''; + + return 'POST' === $request_method; + } + + /** + * Check if it is a WooCommerce AJAX request. + * + * @return bool + */ + public static function is_wc_ajax(): bool { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return isset( $_GET['wc-ajax'] ); + } }