'defer' ) : array();
wp_enqueue_script( 'cfturnstile', 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit', array(), null, $defer );
}
}
add_action( 'wp_enqueue_scripts', 'cfturnstile_sunshine_enqueue_scripts', 10 );
/**
* Add JavaScript to handle AJAX-loaded modal forms.
* Sunshine Photo Cart loads login/signup/reset forms via AJAX into modals.
*/
function cfturnstile_sunshine_modal_scripts() {
// Only add if at least one form integration is enabled.
$login = get_option( 'cfturnstile_sunshine_login' );
$register = get_option( 'cfturnstile_sunshine_register' );
$reset = get_option( 'cfturnstile_sunshine_reset' );
if ( ! $login && ! $register && ! $reset ) {
return;
}
// Only load on Sunshine pages where modals might appear.
if ( function_exists( 'is_sunshine' ) && ! is_sunshine() ) {
return;
}
// Get the site key for explicit rendering.
$key = esc_attr( get_option( 'cfturnstile_key' ) );
if ( empty( $key ) ) {
return;
}
?>
cart ) ) {
SPC()->cart->add_error( cfturnstile_failed_message() );
if ( 'contact' === $section ) {
wp_send_json_error();
}
}
}
}
// Clear on order completion
add_action( 'sunshine_checkout_init_order_success', 'cfturnstile_sunshine_checkout_clear', 10, 1 );
/**
* Clear Turnstile transient data after successful order.
*
* @param object $order The order object.
*/
function cfturnstile_sunshine_checkout_clear( $order ) {
cfturnstile_clear_verified( 'cfturnstile_sunshine_checkout_checked' );
}
/**
* Add JavaScript to handle AJAX-loaded checkout sections.
* Sunshine Photo Cart reloads checkout sections via AJAX, so we need to
* render/reset Turnstile when the payment section loads.
*/
function cfturnstile_sunshine_checkout_scripts() {
// Only load on checkout page.
if ( ! function_exists( 'is_sunshine_page' ) || ! is_sunshine_page( 'checkout' ) ) {
return;
}
// Check if guest only is enabled.
$guest_only = esc_attr( get_option( 'cfturnstile_sunshine_guest_only' ) );
if ( $guest_only && is_user_logged_in() ) {
return;
}
// Get the site key for explicit rendering.
$key = esc_attr( get_option( 'cfturnstile_key' ) );
if ( empty( $key ) ) {
return;
}
?>