Skip to content

Feature Request: Implement Native WP 7.0 AI Client as a new AntiSpam Filter #201

Description

@erikyo

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

  1. Create the New Filter Class:
    Create a new class (e.g., Filter_AI_Semantic) inside core/Filters/ that extends Abstract_CF7_AntiSpam_Filter.

  2. 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.

  3. 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.
  4. 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

  • Create Filter_AI_Semantic.php extending Abstract_CF7_AntiSpam_Filter.
  • Hook the new class into cf7a_spam_check_chain with priority > 20.
  • Integrate the WP 7.0 AI Client call within the process method.
  • Add the new AI reason key to cf7a_score_mapping.
  • Ensure cf7a_log() fires correctly when the AI filter catches spam to aid debugging.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions