From 8e428b16d9dbda77ee58ed9da005069ccbe68121 Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Mon, 16 Dec 2024 13:44:11 +0200 Subject: [PATCH] Fix Cloudflare Turnstile validation for PayPal Express * BUG FIX: Fixed an issue where CloudFlare validation would fail for PayPal Express checkouts, and potentially other gateways. Resolves: https://github.com/strangerstudios/paid-memberships-pro/issues/3212 --- includes/cloudflare-turnstile.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/cloudflare-turnstile.php b/includes/cloudflare-turnstile.php index c441eb366..b26d3a216 100644 --- a/includes/cloudflare-turnstile.php +++ b/includes/cloudflare-turnstile.php @@ -47,6 +47,11 @@ function pmpro_cloudflare_turnstile_validation( $okay ) { return $okay; } + // Don't show it more than once on a screen. This is for "PayPal Express". + if ( pmpro_get_session_var( 'pmpro_cloudflare_turnstile_validated' ) ) { + return $okay; + } + // If the Turnstile is not passed, show an error. if ( empty( $_POST['cf-turnstile-response'] ) ) { pmpro_setMessage( __( 'Please complete the security check.', 'paid-memberships-pro' ), 'pmpro_error' ); @@ -74,6 +79,7 @@ function pmpro_cloudflare_turnstile_validation( $okay ) { $okay = false; } + pmpro_set_session_var( 'pmpro_cloudflare_turnstile_validated', true ); return $okay; } add_action( 'pmpro_checkout_checks', 'pmpro_cloudflare_turnstile_validation' ); @@ -164,3 +170,13 @@ function pmpro_cloudflare_turnstile_get_error_message() { return $error_messages; } + +/** + * Clear the CloudFlare Turnstile session variable after checkout. + * @since TBD + */ +function pmpro_after_checkout_reset_cloudflare_turnstile() { + pmpro_unset_session_var( 'pmpro_cloudflare_turnstile_validated' ); +} +add_action( 'pmpro_after_checkout', 'pmpro_after_checkout_reset_cloudflare_turnstile' ); +add_action( 'pmpro_after_update_billing', 'pmpro_after_checkout_reset_cloudflare_turnstile' ); \ No newline at end of file