WordPress-integratie

Bescherm uw WordPress-formulieren met SilentShield. Werkt met Contact Form 7, WPForms, Gravity Forms en elk aangepast formulier.

1. Het script toevoegen

Voeg deze code toe aan het bestand functions.php van uw thema of gebruik een plugin zoals « Insert Headers and Footers »:

functions.phpphp
// 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. Serververificatie

Voeg Nonce-verificatie toe aan uw formulierverwerking. Voor aangepaste formulieren voegt u dit toe aan uw verwerkingsfunctie:

PHPphp
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

De Widget detecteert automatisch Contact Form 7 formulieren. Er is geen extra configuratie nodig — voeg het script toe en de Widget beschermt alle CF7-formulieren op de pagina.

WPForms / Gravity Forms

SilentShield detecteert automatisch formulieren van WPForms, Gravity Forms en andere populaire formulierplugins. De Widget injecteert de Nonce in elk formulier dat op de pagina wordt gevonden.

De API Key opslaan

Voeg uw API Key toe aan wp-config.php voor extra beveiliging:

wp-config.phpphp
// wp-config.php
define('SILENTSHIELD_API_KEY', 'your-api-key-here');