请先配置 CAP_SITEKEY。

'; } wp_enqueue_script('cap-widget', 'https://cap.bug.im/v1.js', array(), null, true); ob_start(); ?>
405)); } $nonce = isset($_POST['cap_nonce']) && is_string($_POST['cap_nonce']) ? sanitize_text_field(wp_unslash($_POST['cap_nonce'])) : ''; if (!wp_verify_nonce($nonce, 'cap_contact')) { wp_die('表单已失效,请刷新。', '', array('response' => 403)); } if (!defined('CAP_SECRET')) { wp_die('服务端尚未配置。', '', array('response' => 503)); } $token = isset($_POST['cap-response']) && is_string($_POST['cap-response']) ? wp_unslash($_POST['cap-response']) : ''; $message = isset($_POST['message']) && is_string($_POST['message']) ? sanitize_textarea_field(wp_unslash($_POST['message'])) : ''; if (!$token || !$message || strlen($message) > 8000 || strlen($token) > 16384) { wp_die('请填写留言并完成验证。', '', array('response' => 400)); } $check = wp_remote_post('https://cap.bug.im/v1/siteverify', array( 'timeout' => 8, 'headers' => array('Content-Type' => 'application/json'), 'body' => wp_json_encode(array('secret' => CAP_SECRET, 'response' => $token)), )); if (is_wp_error($check) || wp_remote_retrieve_response_code($check) !== 200) { wp_die('暂时无法校验,请重新验证。', '', array('response' => 503)); } $result = json_decode(wp_remote_retrieve_body($check), true); if (!is_array($result) || ($result['success'] ?? false) !== true || !empty($result['degraded'])) { wp_die('验证未通过,请重新验证。', '', array('response' => 403)); } // Persist the sanitized message here, before displaying success. wp_die('验证通过。此示例未保存留言。', '', array('response' => 200)); }