V430 CF7 OpenAI Spam Check
A WordPress plugin that uses OpenAI to classify Contact Form 7 submissions and automatically block spam.
by V430 Digital · github.com/v430digital/v430-digital-openai-spam · website
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/v430digital/v430-digital-openai-spam/archive/refs/heads/main.zipA WordPress plugin that uses OpenAI to classify Contact Form 7 submissions and automatically block spam.
Features
- AI-Powered Spam Detection: Uses OpenAI's GPT-4o-mini model to classify form submissions
- Three-Category Classification: Classifies submissions as
spam,job_request, orlead - Configurable Blocking: Optionally treat job requests as spam
- Fail-Open Design: If API fails, submissions are NOT blocked (reliability first)
- Per-Form Settings: Enable/disable spam detection for individual contact forms
- Privacy Focused: No data stored locally, only sent to OpenAI for analysis
- WordPress Security: Proper nonce verification, capability checks, and input sanitization
Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher
- Contact Form 7 plugin (active)
- OpenAI API key
Installation
- Upload the plugin files to
/wp-content/plugins/v430-cf7-openai-spam/ - Activate the plugin through the WordPress admin
- Go to Contact > OpenAI Anti Spam to configure your API key
- Enable spam detection on individual contact forms
Configuration
1. API Key Setup
- Get an OpenAI API key from OpenAI Platform
- Go to Contact > OpenAI Anti Spam in WordPress admin
- Enter your API key (starts with
sk-) - Click "Test API Connection" to verify it works
2. Form-Level Settings
For each Contact Form 7 form:
- Edit the contact form
- Click the "OpenAi Spam Check" tab
- Check "Enable OpenAI Anti Spam" to activate
- Optionally check "Consider job requests as spam" if you want to block job-related inquiries
How It Works
- When a form is submitted, the plugin collects all field data
- Data is sent to OpenAI with a specific classification prompt
- OpenAI returns one of three labels:
spam,job_request, orlead - Based on your settings:
spam→ Always blockedjob_request→ Blocked only if "Consider job requests as spam" is enabledlead→ Never blocked
Privacy & Security
- No Local Storage: Form data is only sent to OpenAI, never stored by this plugin
- Fail-Open Behavior: If OpenAI API fails, submissions are processed normally (not blocked)
- Minimal Data: Only form field names and values are sent to OpenAI
- WordPress Security: All inputs sanitized, outputs escaped, proper nonce verification
Debugging
Enable debug mode by adding this to your wp-config.php:
define( 'V430_CF7_OPENAI_DEBUG', true );
Debug messages will be logged to your WordPress error log.
API Usage & Costs
- Uses OpenAI's
gpt-4o-minimodel (cost-effective) - Each form submission = 1 API call
- Minimal token usage (form data + short prompt)
- Failed requests are retried once for timeouts/rate limits
Troubleshooting
Plugin Not Working
- Ensure Contact Form 7 is active
- Check that your API key is valid and starts with
sk- - Test API connection in settings
Forms Not Being Checked
- Verify "Enable OpenAI Anti Spam" is checked for the specific form
- Check WordPress error logs if debug mode is enabled
API Errors
- Verify API key hasn't expired
- Check OpenAI account has sufficient credits
- Network connectivity issues usually resolve automatically
Technical Details
WordPress Hooks Used
wpcf7_spam- Spam detection filterwpcf7_editor_panels- Adds editor tabwpcf7_save_contact_form- Saves form settingsadmin_menu- Adds settings page
Classification Prompt
The plugin uses this exact prompt sent to OpenAI:
[ROLE] You are a text classifier.
[CONTEXT] You receive a generic text and must label it.
[GOAL] Return only one of these three labels: spam, job_request, lead.
[CONSTRAINTS] No explanation, no extra text, no symbols.
[OUTPUT SPEC] Output exactly one lowercase word from the allowed labels.
[QUALITY BAR] Output is valid only if it matches one of the 3 labels.
[FAIL-SAFES] If ambiguous → choose the most plausible label without explanation.
[INPUT TEXT]
{form_data}
Developer Hooks
Filters
v430_cf7_openai_model- Change OpenAI model (default:gpt-4o-mini)
Example:
add_filter( 'v430_cf7_openai_model', function() {
return 'gpt-4o'; // Use full GPT-4o model
});
Support
For technical support or feature requests, contact V430 Digital at https://v430.it
License
GPL v2 or later
Changelog
1.0.0
- Initial release
- OpenAI GPT-4o-mini integration
- Three-category classification (spam/job_request/lead)
- Per-form enable/disable settings
- Fail-open error handling
- WordPress admin integration