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 Cloudflare Turnstile validation for PayPal Express #3232

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
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' );