Description
WordPress 7.0 introduces a native AI infrastructure (AI Client and Abilities API). We should leverage this feature to perform advanced semantic spam analysis. Instead of relying on hardcoded third-party API keys, we can delegate the evaluation to the global AI provider already configured by the site administrator in the WP 7.0 Connectors dashboard.
This feature needs to be integrated seamlessly into our existing cf7a_spam_check_chain architecture.
Proposed Implementation
-
Create the New Filter Class:
Create a new class (e.g., Filter_AI_Semantic) inside core/Filters/ that extends Abstract_CF7_AntiSpam_Filter.
-
Register the Filter in the Chain:
In CF7_AntiSpam_Filters::__construct(), add the new filter to cf7a_spam_check_chain.
Note: It should be hooked with a very late priority (e.g., 30, after Filter_B8_Bayesian which is at 20). This ensures we don't waste time and API calls making remote AI requests if standard filters (like Filter_Bad_Words or Filter_IP_Blocklist_History) have already determined the payload is spam.
-
Implement the process( array $data ) Logic:
- Compatibility Check: Verify if the WP 7.0 AI Client is available and an active provider is configured. If not, return
$data immediately.
- Prompt Construction: Extract
$data['message'] and build a system prompt for the LLM to act as a semantic spam evaluator.
- Scoring Context: If the AI detects spam, append the violation to the context:
$data['reasons']['ai_semantic_spam'][] = 'Semantic evaluation failed';.
- Remember to implement proper timeout handling to ensure the form submission doesn't hang indefinitely if the AI service is unresponsive.
-
Update Score Mapping:
Update the default array inside the cf7a_score_mapping filter in CF7_AntiSpam_Filters::cf7a_spam_filter().
We need to map the new reason key (e.g., 'ai_semantic_spam' => '_detection') so the orchestrator correctly calculates the $spam_data['spam_score'] and logs the action.
Technical Tasks
Description
WordPress 7.0 introduces a native AI infrastructure (AI Client and Abilities API). We should leverage this feature to perform advanced semantic spam analysis. Instead of relying on hardcoded third-party API keys, we can delegate the evaluation to the global AI provider already configured by the site administrator in the WP 7.0 Connectors dashboard.
This feature needs to be integrated seamlessly into our existing
cf7a_spam_check_chainarchitecture.Proposed Implementation
Create the New Filter Class:
Create a new class (e.g.,
Filter_AI_Semantic) insidecore/Filters/that extendsAbstract_CF7_AntiSpam_Filter.Register the Filter in the Chain:
In
CF7_AntiSpam_Filters::__construct(), add the new filter tocf7a_spam_check_chain.Note: It should be hooked with a very late priority (e.g.,
30, afterFilter_B8_Bayesianwhich is at20). This ensures we don't waste time and API calls making remote AI requests if standard filters (likeFilter_Bad_WordsorFilter_IP_Blocklist_History) have already determined the payload is spam.Implement the
process( array $data )Logic:$dataimmediately.$data['message']and build a system prompt for the LLM to act as a semantic spam evaluator.$data['reasons']['ai_semantic_spam'][] = 'Semantic evaluation failed';.Update Score Mapping:
Update the default array inside the
cf7a_score_mappingfilter inCF7_AntiSpam_Filters::cf7a_spam_filter().We need to map the new reason key (e.g.,
'ai_semantic_spam' => '_detection') so the orchestrator correctly calculates the$spam_data['spam_score']and logs the action.Technical Tasks
Filter_AI_Semantic.phpextendingAbstract_CF7_AntiSpam_Filter.cf7a_spam_check_chainwith priority > 20.processmethod.cf7a_score_mapping.cf7a_log()fires correctly when the AI filter catches spam to aid debugging.