Spam trap in the comment form
Adds a hidden field that people never see but bots fill in. Comments that fill it in are refused. No captcha, nothing sent to other companies.
<?php
// A field hidden from people (and from screen readers); bots fill every field.
$snipfire_trap = static function () {
echo '<p class="snipfire-hp" aria-hidden="true" style="position:absolute;left:-9999px;height:0;overflow:hidden">'
. '<label>Leave this empty <input type="text" name="snipfire_hp_website" value="" tabindex="-1" autocomplete="off"></label></p>';
};
add_action( 'comment_form_after_fields', $snipfire_trap );
add_action( 'comment_form_logged_in_after', $snipfire_trap );
add_filter(
'preprocess_comment',
static function ( $comment ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Comment form, checked by WordPress.
if ( ! empty( $_POST['snipfire_hp_website'] ) ) {
wp_die( esc_html__( 'Comment Submission Failure' ), esc_html__( 'Comment Submission Failure' ), array( 'response' => 403 ) );
}
return $comment;
}
);
In these packs
- Comments: Fewer spam comments and more control: close old posts, set minimum and maximum lengths, a spam trap, no links.