Skip to content

Commit

Permalink
Fix Cloudflare Turnstile validation for PayPal Express
Browse files Browse the repository at this point in the history
* BUG FIX: Fixed an issue where CloudFlare validation would fail for PayPal Express checkouts, and potentially other gateways.

Resolves: strangerstudios#3212
  • Loading branch information
andrewlimaza committed Dec 16, 2024
1 parent be400bc commit 8e428b1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions includes/cloudflare-turnstile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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' );

0 comments on commit 8e428b1

Please sign in to comment.