Created
November 9, 2019 00:41
-
-
Save martinbkaiser/66ba067f36786ac01eea163685513a49 to your computer and use it in GitHub Desktop.
Gravity Forms Profanity Filter/Detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put in your themes functions.php file | |
add_filter( 'gform_pre_send_email', 'before_email', 10, 3); | |
function before_email( $email, $form, $entry ) { | |
// Add your own words to the array, or convert a CSV like I did | |
$swear_array = ['very','bad','language','word','array']; | |
$swear_alert = ""; | |
$email_message = strval(strip_tags($email['message'])); | |
foreach ($swear_array as $swear) { | |
if (preg_match("/\b".$swear."\b/i", $email_message)) { | |
// Profanity detected | |
$swear_alert = "(PROFANITY ALERT)"; | |
}else{ | |
// No bad language detected | |
} | |
} | |
$email['subject'] .= ' '.$swear_alert; | |
return $email; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment