', esc_attr( $site_key ) ); } /** * Verify CAPTCHA response * * @param string $response CAPTCHA response token * @param string $secret_key Secret key * @param string $remote_ip Client IP * @return array */ public function verify( $response, $secret_key, $remote_ip ) { if ( empty( $response ) ) { return array( 'success' => false, 'error' => __( 'CAPTCHA response is missing.', 'subtleforms' ), ); } // phpcs:ignore PluginCheck.CodeAnalysis.Offloading.OffloadedContent -- Cloudflare's own verification endpoint. Turnstile cannot be verified anywhere else, and this is the service the site owner explicitly opted into by configuring it. $verify_url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'; $body = array( 'secret' => $secret_key, 'response' => $response, 'remoteip' => $remote_ip, ); $request = wp_remote_post( $verify_url, array( 'body' => $body, 'timeout' => 10, ) ); if ( is_wp_error( $request ) ) { return array( 'success' => false, 'error' => __( 'CAPTCHA verification request failed.', 'subtleforms' ), ); } $response_body = wp_remote_retrieve_body( $request ); $result = json_decode( $response_body, true ); if ( ! empty( $result['success'] ) ) { return array( 'success' => true ); } $error_codes = $result['error-codes'] ?? array(); return array( 'success' => false, 'error' => __( 'CAPTCHA verification failed.', 'subtleforms' ) . ' (' . implode( ', ', $error_codes ) . ')', ); } /** * Get JavaScript URL * * @param array $config * @return string */ public function getScriptUrl( $config ) { // phpcs:ignore PluginCheck.CodeAnalysis.Offloading.OffloadedContent -- Cloudflare's own widget script. A CAPTCHA that runs from a local copy provides no protection, so this must be loaded from the provider. return 'https://challenges.cloudflare.com/turnstile/v0/api.js'; } }