Skip to content

fix: add honeypot support for an input comment field - #852

Open
faisalahammad wants to merge 3 commits into
pluginkollektiv:v3from
faisalahammad:fix/738-honeypot-input-alternative
Open

fix: add honeypot support for an input comment field#852
faisalahammad wants to merge 3 commits into
pluginkollektiv:v3from
faisalahammad:fix/738-honeypot-input-alternative

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Aug 24, 2026

Copy link
Copy Markdown

Summary

Add honeypot support for themes that render the comment field as a text <input> instead of a <textarea>. Previously the honeypot renderer only handled a textarea, so an input-based comment form got no honeypot at all. The plugin now injects a honeypot that matches the field type automatically, with no new setting.

Fixes #738

Changes

src/Helpers/Honeypot.php

Add an input case to the switch in inject().

For a textarea form nothing changes. For an input form, the visible input keeps its id and class but gets an obfuscated name, and a hidden duplicate input that carries name="comment" is appended right after it as the bait. That mirrors how the textarea case traps the honeypot, so the existing check side of the rule keeps working unchanged.

Why: themes that output the comment field as <input type="text"> had no honeypot, so honeypot-dependent spam protection was silently missing on those sites.

Testing

Test 1: Textarea form regression

  1. Leave the default <textarea name="comment" id="comment"> in place.
  2. View source, confirm a hidden honeypot textarea is present.
  3. Blank submit: normal empty error, no spam flag.
  4. Normal comment: posts and is not flagged as honeypot spam.
  5. Fill the hidden honeypot textarea: comment flagged spam.
    Result: unchanged behavior from before this fix.

Test 2: Input form

  1. Replace the comment field with <input type="text" id="comment" name="comment" class="comment-field">.
  2. View source, confirm the visible input keeps id and class but has an obfuscated name, and a hidden honeypot input with name="comment" is inserted after it.
  3. Blank submit: normal empty error, no spam flag.
  4. Normal comment: accepted, not flagged as honeypot spam.
  5. Fill the hidden honeypot input: comment flagged spam.
    Result: input-based comment forms now have a working honeypot.

Test 3: Prefixed fields

  1. Add <input id="comment-extra" name="comment-extra"> before the real comment field.
  2. Confirm the real comment field is rewritten and comment-extra is left untouched.
    Result: prefixed fields are not mistaken for the comment field.

Screenshot

SCR-20260824-uhqr

- Use the core is-dismissible close button and drop the hand-rolled one.
- Keep i18n one translatable string per message.
- Persist dismissal keyed to PR PLUGIN_VERSION so it returns on newer builds.
- Fold is_pre_release into PreReleaseNotice and allow build metadata.
- Deny without capability via wp_send_json_error(403) or wp_die('', 403).
- Rename the dismiss script to pre-release-notice.js and persist on X clicks.
Add an input case to the honeypot renderer so themes that output the
comment field as a text input get a working honeypot. The visible input
keeps its id and gets an obfuscated name, and a hidden duplicate with
the comment name is appended as the bait, matching how the textarea
case works.

Fixes pluginkollektiv#738
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