Skip to content

A spam/ham correction obeys the form's Akismet switch, not just Akismet's presence - #49

Merged
AllTerrainDeveloper merged 1 commit into
mainfrom
fix/akismet-corrections-respect-form-opt-in
Sep 1, 2026
Merged

AllTerrainDeveloper merged 1 commit into
mainfrom
fix/akismet-corrections-respect-form-opt-in

Conversation

@AllTerrainDeveloper

Copy link
Copy Markdown
Owner

What the reviewer flagged

Marking any entry as spam or ham sends its contents, IP address and user agent to Akismet whenever Akismet is configured, without checking the form's opt-in Akismet setting.

Correct. alltfo_akismet_submit_correction() checked only alltfo_akismet_available() (plugin installed + API key). The submission-time check already honoured the form's spam.akismet switch (off by default); the correction path skipped it.

The fix

  • includes/spam.php
    • New alltfo_form_uses_akismet( $schema ) — the single gate every Akismet request passes through. Reads only the form's own spam.akismet switch.
    • alltfo_akismet_submit_correction() looks up the entry's form (_alltfo_form meta) and returns before Akismet is even looked for unless that form opted in. Now returns bool (whether anything was sent).
    • alltfo_screen_for_spam() uses the same gate.
  • includes/entries.php — docblock on alltfo_set_entry_status() says what actually happens.
  • readme.txt — External services now states explicitly that spam/ham corrections obey the per-form switch.

Net: with Akismet off on a form (the default), nothing about its entries ever reaches Akismet — not on submission, not when someone clicks spam / not-spam — regardless of whether the Akismet plugin is installed and configured on the site.

Tests

New tests/phpunit/tests/akismet.php (5 tests, 25 assertions) against a recording stand-in for the Akismet class (tests/phpunit/stubs/class-akismet.php, guarded by class_exists):

  • Form with Akismet off + Akismet plugin configured → mark spam, then not-spam → zero requests; direct call returns false.
  • Form with Akismet on → exactly submit-spam then submit-ham; marking spam twice is one correction.
  • Form on but Akismet unconfigured → nothing sent; a non-entry post → nothing sent.
  • Screening: off → no comment-check; on → exactly one comment-check, verdict akismet.

Full suite: 749 tests, 3542 assertions, OK. PHPCS clean on new/changed code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DVAaHFURDGeBzeuWHZ2dcP

…et's presence

The WordPress.org review flagged it: marking an entry as spam or not-spam
sent its contents, IP address and user agent to Akismet whenever the Akismet
plugin was configured, without consulting the form's own opt-in setting. The
check on submission already honoured that switch; the correction did not.

`alltfo_akismet_submit_correction()` now looks up the entry's form and returns
before touching Akismet unless that form has `spam.akismet` on. The same test,
`alltfo_form_uses_akismet()`, is now the single gate both code paths pass
through, so no request to Akismet can be made on behalf of a form that never
opted in. The function returns whether a correction was sent.

Tests exercise both paths against a recording stand-in for Akismet: a form
with Akismet off produces zero requests on submission and on either
correction, even with an API key configured; a form with it on produces
exactly one comment-check, one submit-spam and one submit-ham. readme.txt's
External services section now states that corrections obey the per-form
switch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DVAaHFURDGeBzeuWHZ2dcP
@AllTerrainDeveloper
AllTerrainDeveloper merged commit d86b9dd into main Sep 1, 2026
3 checks passed
@AllTerrainDeveloper
AllTerrainDeveloper deleted the fix/akismet-corrections-respect-form-opt-in branch September 1, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant