Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Replace word in Post

I just finished uploading talkPress 002: A Simple bbPress Plugin – Bad Words Filter. You can watch this here.

The code mentioned in video is:

<?php
/*
Plugin Name: Bad Words Filter
Plugin URI: http://www.livibetter.com/
Description: Removing bad words from post content
Author: Yu-Jie Lin
Author URI: http://www.livibetter.com/
Version: 0.1
*/

function BadWordsFilter($post_text) {
// $post_text = str_ireplace('bad', '*****', $post_text);

$bad_words = array('bad', 'topic', 'cialis');
foreach($bad_words as $bad)
// $post_text = str_ireplace($bad, '*****', $post_text);
$post_text = preg_replace("/\b$bad\b/i", '*****', $post_text);

return $post_text;
}

add_filter('post_text', 'BadWordsFilter');
?>

Skip to toolbar