*/ public static function defaults(): array { return [ 'site_key' => '', 'secret_key' => '', 'consent_position' => 'before-submit', 'fail_open' => 0, 'protect_comments' => 1, 'protect_login' => 1, 'protect_registration' => 1, 'protect_cf7' => 1, 'protect_wpforms' => 0, 'protect_gravity' => 0, 'protect_ninja' => 0, 'protect_elementor' => 0, 'protect_formidable' => 0, 'protect_fluent' => 0, 'protect_woocommerce' => 0, 'custom_selectors' => '', 'widget_id' => '', ]; } /** * @return array */ public static function get(): array { $stored = get_option(self::OPTION, []); if (!is_array($stored)) { $stored = []; } return array_merge(self::defaults(), $stored); } public static function isConfigured(): bool { $settings = self::get(); return trim((string) $settings['site_key']) !== '' && trim((string) $settings['secret_key']) !== ''; } public static function register(): void { register_setting('gateform', self::OPTION, [ 'type' => 'array', 'sanitize_callback' => [self::class, 'sanitize'], 'default' => self::defaults(), ]); } /** * @param mixed $input * @return array */ public static function sanitize($input): array { $input = is_array($input) ? $input : []; return [ 'site_key' => sanitize_text_field((string) ($input['site_key'] ?? '')), 'secret_key' => sanitize_text_field((string) ($input['secret_key'] ?? '')), 'consent_position' => self::sanitizeConsentPosition((string) ($input['consent_position'] ?? '')), 'fail_open' => empty($input['fail_open']) ? 0 : 1, 'protect_comments' => empty($input['protect_comments']) ? 0 : 1, 'protect_login' => empty($input['protect_login']) ? 0 : 1, 'protect_registration' => empty($input['protect_registration']) ? 0 : 1, 'protect_cf7' => empty($input['protect_cf7']) ? 0 : 1, 'protect_wpforms' => empty($input['protect_wpforms']) ? 0 : 1, 'protect_gravity' => empty($input['protect_gravity']) ? 0 : 1, 'protect_ninja' => empty($input['protect_ninja']) ? 0 : 1, 'protect_elementor' => empty($input['protect_elementor']) ? 0 : 1, 'protect_formidable' => empty($input['protect_formidable']) ? 0 : 1, 'protect_fluent' => empty($input['protect_fluent']) ? 0 : 1, 'protect_woocommerce' => empty($input['protect_woocommerce']) ? 0 : 1, 'custom_selectors' => self::sanitizeSelectors((string) ($input['custom_selectors'] ?? '')), 'widget_id' => self::sanitizeWidgetId((string) ($input['widget_id'] ?? '')), ]; } private static function sanitizeWidgetId(string $value): string { $id = trim($value); if ($id === '') { return ''; } if (preg_match('/^[A-Za-z0-9_-]{3,64}$/', $id) !== 1) { add_settings_error( self::OPTION, 'gateform_widget_id_invalid', 'ID виджета связи может содержать латинские буквы, цифры, дефис и подчёркивание.' ); return ''; } return $id; } private static function sanitizeConsentPosition(string $value): string { $position = sanitize_key($value); return in_array($position, ['start', 'before-submit', 'after-submit', 'end'], true) ? $position : 'before-submit'; } public static function sanitizeSelectors(string $value): string { $parts = preg_split('/[\r\n,]+/', $value) ?: []; $selectors = []; foreach ($parts as $part) { $selector = trim((string) $part); if ($selector === '' || strlen($selector) > 120) { continue; } if (!preg_match('/^[A-Za-z0-9_#.\-\[\]="\': >+~*]+$/', $selector)) { continue; } if (!in_array($selector, $selectors, true)) { $selectors[] = $selector; } if (count($selectors) >= 20) { break; } } return implode("\n", $selectors); } /** * @return list */ public static function customSelectors(): array { $raw = (string) (self::get()['custom_selectors'] ?? ''); return array_values(array_filter(array_map('trim', preg_split('/[\r\n,]+/', $raw) ?: []))); } private static function renderToggle(string $key, string $label, string $plugin = ''): void { $settings = self::get(); $active = $plugin !== '' && self::isPluginActive($plugin); printf( '
', esc_attr(self::OPTION), esc_attr($key), checked(1, (int) ($settings[$key] ?? 0), false), esc_html($label), $active ? ' — плагин активен' : '' ); } private static function isPluginActive(string $plugin): bool { $files = [ 'cf7' => 'contact-form-7/wp-contact-form-7.php', 'wpforms' => 'wpforms-lite/wpforms.php', 'gravity' => 'gravityforms/gravityforms.php', 'ninja' => 'ninja-forms/ninja-forms.php', 'elementor' => 'elementor-pro/elementor-pro.php', 'formidable' => 'formidable/formidable.php', 'fluent' => 'fluentform/fluentform.php', 'woocommerce' => 'woocommerce/woocommerce.php', ]; if (isset($files[$plugin]) && function_exists('is_plugin_active')) { return is_plugin_active($files[$plugin]); } return match ($plugin) { 'cf7' => defined('WPCF7_VERSION') || class_exists('WPCF7'), 'wpforms' => function_exists('wpforms'), 'gravity' => class_exists('GFForms'), 'ninja' => function_exists('Ninja_Forms'), 'elementor' => class_exists('ElementorPro\\Plugin'), 'formidable' => class_exists('FrmAppHelper'), 'fluent' => defined('FLUENTFORM'), 'woocommerce' => class_exists('WooCommerce'), default => false, }; } public static function renderPage(): void { if (!current_user_can('manage_options')) { return; } $settings = self::get(); ?>

GateForm gateform.ru

Укажите публичный и секретный ключи — без них защита не работает.


Contact Form 7

Капча включается галочкой «Contact Form 7» выше. В форму можно добавить тег [gateform] — он выведет скрытое поле токена и подпись со ссылкой на GateForm. Без тега client.js добавит поле автоматически, а подпись будет добавлена в конец формы.

Проверка выполняется фильтром wpcf7_validate до отправки письма. При отказе форма покажет сообщение об ошибке и не отправит письмо.

Как это работает

Плагин подключает client.js только на страницы с защищёнными формами. Скрипт собирает поведенческие сигналы и добавляет в форму скрытое поле gf_token. Токен проверяется на сервере GateForm.

IP-адреса посетителей плагин не сохраняет. Значения полей формы на сервис проверки не передаются.

Документация: gateform.ru/docs. Плагин: gateform.ru/integrations/wordpress.