Please or Register to create posts and topics.

Post lock for banned words

Hello Asgaros,

I want to block posts that contain certain words, also to avoid spam posts.

Now I have found the following code for replacing words:

function wordFilter($text)
{
$filter_terms = array(

‘word 1’,
‘word 2’,
‘word 3’);

$filtered_text = $text;
foreach($filter_terms as $word)
{
$match_count = preg_match_all(‘/’ . $word . ‘/i’, $text, $matches);
for($i = 0; $i < $match_count; $i++)
{
$bwstr = trim($matches[0][$i]);
$filtered_text = preg_replace(‘/\b’ . $bwstr . ‘\b/’, str_repeat(“*”, strlen($bwstr)), $filtered_text);
}
}
return $filtered_text;
}

add_filter(‘asgarosforum_filter_post_content’, ‘wordFilter’);

Is there a way to prevent the post from being sent if certain words are included?

Best regards,

Markus