Forum breadcrumbs – You are here:Asgaros Support ForumSupportProfanity filter?
Please or Register to create posts and topics.

Profanity filter?

Page 1 of 2Next

is there a way to filter out inappropriate words?

Hi shermtech,

function customforumcontent($content) {
$censored = array( 
    'word 1',
    'word 2',
    'word 3',
);
$replace = '<b>[censored]</b>';
$content = str_replace($censored, $replace, $content);
  return $content;
}
add_filter('asgarosforum_filter_post_content', 'customforumcontent');

 

sorry to ask, but where would i insert that piece of code? Also thanks for your reply.

To do this you just have to add this code to your themes functions.php file

Thanks for the code. Bu when I use this, it filters all the syllables and It’s impossible to write a proper thing. How can i prevent this?

Hello selch,

how does your code looks like?

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Hello again,

I used the same code you gave here;

 

  1. function customforumcontent($content) {
  2. $censored = array(
  3. ‘word 1’,
  4. ‘word 2’,
  5. ‘word 3’,
  6. );
  7. $replace = ‘<b>[censored]</b>’;
  8. $content = str_replace($censored, $replace, $content);
  9. return $content;
  10. }
  11. add_filter(‘asgarosforum_filter_post_content’, ‘customforumcontent’);

I figured it out, thank you for your help, if necessary i’m putting my version here:

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');

 

Asgaros has reacted to this post.
Asgaros

I am glad to hear that you found a working solution. 🙂

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!
Hello,
what is the funtion of this code? Only replace words or replace links, too?
Regards
Olli
Quote from selch on February 3, 2018, 12:18 pm

I figured it out, thank you for your help, if necessary i’m putting my version here:

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');

  1. function wordFilter($text)
  2. {
  3. $filter_terms = array(
  4. ‘word 1’,
  5. ‘word 2’,
  6. ‘word 3’);
  7. $filtered_text = $text;
  8. foreach($filter_terms as $word)
  9. {
  10. $match_count = preg_match_all(‘/’ . $word . ‘/i’, $text, $matches);
  11. for($i = 0; $i < $match_count; $i++)
  12. {
  13. $bwstr = trim($matches[0][$i]);
  14. $filtered_text = preg_replace(‘/\b’ . $bwstr . ‘\b/’, str_repeat(“*”, strlen($bwstr)), $filtered_text);
  15. }
  16. }
  17. return $filtered_text;
  18. }
  19. add_filter(‘asgarosforum_filter_post_content’, ‘wordFilter’);
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');

 

 

Page 1 of 2Next