I am developing a swear filter plugin for my blog. It is supposed to deny submissions containing any words in a text file called swears.txt
. Here is the code I am using for the comment form on single post page:
<?php
if (isset($_POST['submit'])) {
echo 'Submitted'; // for debugging purposes
$swearsFile = 'swears.txt';
$swearsCntnt = file_get_contents($swearsFile);
$swearList = explode("\n", $swearsCntnt);
$swearWords = "/";
for ($i = 0; $i < count($swearList); ++$i) {
if ($i == 0)
$swearWords .= rtrim($swearList[$i]);
else
$swearWords .= "|" . rtrim($swearList[$i]);
}
$swearWords .= "/i";
if (preg_match($swearWords, $_POST['comment'])) {
wp_die( __( '<strong>ERROR</strong>: You have entered forbidden text. Please consider revising.' ), 200 );
}
}
?>
The problem is that nothing happens after I press the Post Comment button except that the submitted comment appears as a new one. I am using an echo to verify that the Post Comment button has been pressed whether or not its following statements return true, yet nothing happens. How do I get WordPress to acknowledge if (isset($_POST['submit']))
?