WordPressインテグレーション
SilentShieldでWordPressフォームを保護しましょう。Contact Form 7、WPForms、Gravity Forms、およびカスタムフォームに対応しています。
1. スクリプトを追加する
テーマのfunctions.phpに以下のコードを追加するか、「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. サーバーサイド検証
フォームハンドラーにNonce検証を追加します。カスタムフォームの場合は、処理関数に以下を追加してください:
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
ウィジェットはContact Form 7のフォームを自動的に検出します。追加の設定は不要です。スクリプトを追加するだけで、ページ上のすべてのCF7フォームが保護されます。
WPForms / Gravity Forms
SilentShieldはWPForms、Gravity Forms、およびその他の人気フォームプラグインのフォームを自動的に検出します。ウィジェットはページ上で見つけたすべてのフォームにNonceを挿入します。
APIキーの保存
セキュリティのため、APIキーをwp-config.phpに追加してください:
wp-config.phpphp
// wp-config.php
define('SILENTSHIELD_API_KEY', 'your-api-key-here');