Hi @designnewdaymediacom
I hope you are doing well.
Can you test this version on your Staging or Development site?
<?php
/**
* Plugin Name: [Forminator] - Banned words
* Plugin URI: https://premium.wpmudev.org/
* Description: Banned words check for Forminator.
* Author: Panos Lyrakis @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
if ( ! class_exists( 'WPMUDEV_Forminator_Banned_Words' ) ) {
class WPMUDEV_Forminator_Banned_Words {
private $error_message = 'There were some banned words found in your submission';
private static $_instance = null;
private $filter_error_message = false;
public static function get_instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
private function __construct() {
add_filter( 'forminator_custom_form_submit_errors', array( $this, 'control_words' ), 10, 3 );
add_filter( 'forminator_custom_form_invalid_form_message', array( $this, 'filter_error_message' ) );
}
public function control_words( $submit_errors, $form_id, $field_data_array ) {
$csv_file = WP_CONTENT_DIR . '/mu-plugins/bannedwords.csv';
foreach( $field_data_array as $key => $value ) {
if( isset ( $value[ 'form_field_obj' ] ) ) {
unset( $field_data_array[ $key ][ 'form_field_obj' ] );
}
}
if ( file_exists( $csv_file ) && is_readable( $csv_file ) ) {
$fields_words = implode(
' ',
array_map(
function( $a ) {
return implode( ' ', $a );
},
$field_data_array
)
);
$banned_words = array_map(
function( $csv ) {
return $csv[0];
},
array_map( 'str_getcsv', file( $csv_file ) )
);
$banned_words = implode( '|', $banned_words );
$banned_words = preg_replace( '/[^\w_|]+/u', '', $banned_words );
$matches = array();
$match_found = preg_match(
'(' . $banned_words . ')',
$fields_words,
$matches
);
if ( $match_found && ! empty( $matches ) ) {
// We need somehting here so that the <code>$submit_errors</code> array is not empty.
$submit_errors[] = array( $matches );
$this->filter_error_message = true;
}
}
return $submit_errors;
}
public function filter_error_message( $invalid_form_message ) {
if ( $this->filter_error_message ) {
$invalid_form_message = __( $this->error_message );
}
return $invalid_form_message;
}
}
if ( ! function_exists( 'wpmudev_forminator_banned_words' ) ) {
function wpmudev_forminator_banned_words() {
return WPMUDEV_Forminator_Banned_Words::get_instance();
};
add_action( 'plugins_loaded', 'wpmudev_forminator_banned_words', 10 );
}
}
The bannedwords.csv must be uploaded inside the wp-content > mu-plugins.
Best Regards
Patrick Freitas