Skip to content

Instantly share code, notes, and snippets.

@adczk
Created October 18, 2021 16:44
Show Gist options
  • Select an option

  • Save adczk/896f53970d4977cfea417b941448760d to your computer and use it in GitHub Desktop.

Select an option

Save adczk/896f53970d4977cfea417b941448760d to your computer and use it in GitHub Desktop.
Forminator 1.15.3 - very basic "stop-words" type spam filter for forms
<?php
/**
* Plugin Name: [Forminator] - very simple "stop words" type spam protection for forms
* Description: prevents submission if defined fields contain defined strings
* Author: Adam @ WPMUDEV
* Author URI: https://wpmudev.com
* License: GPLv2 or later
*
* Tested with Forminator 1.15.3 (backwards/future compatibility unknown)
*/
add_filter( 'forminator_spam_protection', 'wpmu_forminator_stop_words', 10, 4);
function wpmu_forminator_stop_words( $is_spam, $field_data_array, $form_id, $module ) {
// define "stop words" below; as in example;
// if there are these strings in defined fields
// form will return "something went wrong" error and not get submitted
$stopwords = array(
'test',
'something',
'[email protected]'
);
// define fields to check
$fields_to_check = array('textarea-1', 'text-1');
foreach( $field_data_array as $field ) {
if ( in_array( $field['name'], $fields_to_check ) ) {
foreach( $stopwords as $word ) {
if ( stripos( $field['value'], $word ) !== false ) {
$is_spam = true;
}
}
}
}
return $is_spam;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment