WordPress-integration
Beskyt dine WordPress-formularer med SilentShield. Fungerer med Contact Form 7, WPForms, Gravity Forms og alle tilpassede formularer.
1. Tilføj scriptet
Tilføj denne kode til dit temas functions.php eller brug et plugin som »Insert Headers and Footers«:
// functions.php
function silentshield_enqueue() {
wp_enqueue_script(
'silentshield',
'https://api.silentshield.io/client.js?key=YOUR_API_KEY',
array(),
null,
true
);
wp_add_inline_script('silentshield', "
document.addEventListener('DOMContentLoaded', function() {
SilentShield.init({ apiKey: 'YOUR_API_KEY' });
});
");
}
add_action('wp_enqueue_scripts', 'silentshield_enqueue');2. Serversideverificering
Tilføj nonce-verificering til din formular-handler. For tilpassede formularer, tilføj dette til din behandlingsfunktion:
function verify_silentshield_nonce() {
$nonce = sanitize_text_field($_POST['ss_nonce'] ?? '');
if (empty($nonce)) {
wp_die('Missing verification', 'Error', array('response' => 422));
}
$response = wp_remote_post('https://api.silentshield.io/api/v1/captcha/verify-nonce', array(
'headers' => array(
'Content-Type' => 'application/json',
'X-Api-Key' => SILENTSHIELD_API_KEY,
),
'body' => wp_json_encode(array('nonce' => $nonce)),
'timeout' => 5,
));
if (is_wp_error($response)) {
return; // fail open
}
$body = json_decode(wp_remote_retrieve_body($response), true);
if (($body['verdict'] ?? '') === 'bot') {
wp_die('Bot detected', 'Forbidden', array('response' => 403));
}
}Contact Form 7
Widgetten registrerer automatisk Contact Form 7-formularer. Ingen yderligere konfiguration er nødvendig — tilføj bare scriptet, og widgetten vil beskytte alle CF7-formularer på siden.
WPForms / Gravity Forms
SilentShield registrerer automatisk formularer fra WPForms, Gravity Forms og andre populære formularplugins. Widgetten injicerer nonce i enhver formular, den finder på siden.
Opbevaring af API-nøglen
Tilføj din API-nøgle til wp-config.php for sikkerhed:
// wp-config.php
define('SILENTSHIELD_API_KEY', 'your-api-key-here');