[ 'name' => 'hCaptcha', 'desc' => __( 'Privacy focused CAPTCHA that pays website owners. A drop in replacement for reCAPTCHA.', 'phemightforms' ), 'link' => 'https://dashboard.hcaptcha.com/sites', 'logo' => 'hcaptcha', ], 'recaptcha_v2' => [ 'name' => 'reCAPTCHA', 'desc' => __( 'Google reCAPTCHA v2 checkbox: the classic "I\'m not a robot" box trusted across the web.', 'phemightforms' ), 'link' => 'https://www.google.com/recaptcha/admin', 'logo' => 'recaptcha', ], 'turnstile' => [ 'name' => 'Turnstile', 'desc' => __( 'Cloudflare\'s invisible, user friendly CAPTCHA alternative. No puzzles for most visitors.', 'phemightforms' ), 'link' => 'https://dash.cloudflare.com/?to=/:account/turnstile', 'logo' => 'turnstile', ], '' => [ 'name' => __( 'None', 'phemightforms' ), 'desc' => __( 'No CAPTCHA on your forms. The built in honeypot still quietly blocks most bots.', 'phemightforms' ), 'link' => '', 'logo' => 'none', ], ]; } /** * Persist the CAPTCHA settings. */ public function handle_save() { if ( ! current_user_can( Admin::CAPABILITY ) ) { wp_die( esc_html__( 'Permission denied.', 'phemightforms' ) ); } check_admin_referer( 'phemightforms_captcha' ); $settings = get_option( 'phemightforms_settings', [] ); $provider = isset( $_POST['captcha_provider'] ) ? sanitize_key( wp_unslash( $_POST['captcha_provider'] ) ) : ''; if ( ! in_array( $provider, [ '', 'recaptcha_v2', 'hcaptcha', 'turnstile' ], true ) ) { $provider = ''; } $settings['captcha_provider'] = $provider; $settings['captcha_site_key'] = isset( $_POST['captcha_site_key'] ) ? sanitize_text_field( wp_unslash( $_POST['captcha_site_key'] ) ) : ''; $secret = isset( $_POST['captcha_secret_key'] ) ? sanitize_text_field( wp_unslash( $_POST['captcha_secret_key'] ) ) : ''; if ( '' !== $secret ) { $settings['captcha_secret_key'] = $secret; } update_option( 'phemightforms_settings', $settings ); wp_safe_redirect( add_query_arg( [ 'page' => Admin::SLUG . '-captcha', 'saved' => 1, ], admin_url( 'admin.php' ) ) ); exit; } /** * Render the CAPTCHA settings page. */ public static function render_page() { if ( ! current_user_can( Admin::CAPABILITY ) ) { wp_die( esc_html__( 'Permission denied.', 'phemightforms' ) ); } $settings = get_option( 'phemightforms_settings', [] ); $current = isset( $settings['captcha_provider'] ) ? $settings['captcha_provider'] : ''; $site_key = isset( $settings['captcha_site_key'] ) ? $settings['captcha_site_key'] : ''; $secret = isset( $settings['captcha_secret_key'] ) ? $settings['captcha_secret_key'] : ''; $active = Captcha::is_active(); ?>

$provider ) : ?>
>

'> →

( function () { var cards = document.querySelectorAll( '.phf-captcha-card' ); var keys = document.querySelector( '.phf-captcha-keys' ); var hint = document.querySelector( '.phf-captcha-keys-hint' ); var link = document.querySelector( '.phf-captcha-keys-link' ); var links = hint ? JSON.parse( hint.getAttribute( 'data-links' ) || '{}' ) : {}; function update() { var value = ''; cards.forEach( function ( card ) { var input = card.querySelector( 'input' ); card.classList.toggle( 'is-selected', input.checked ); if ( input.checked ) { value = input.value; } } ); if ( keys ) { keys.style.display = value ? '' : 'none'; } if ( link ) { if ( value && links[ value ] ) { link.href = links[ value ]; link.style.display = ''; } else { link.style.display = 'none'; } } } cards.forEach( function ( card ) { card.querySelector( 'input' ).addEventListener( 'change', update ); } ); update(); } )();