The MU forums have moved to WordPress.org

Censor (9 posts)

  1. lucky2
    Member
    Posted 17 years ago #

    How do I censor certain words in blog and post titles? I see the place for "comment" blacklists but is there an application for blogs and posts?

  2. lunabyte
    Member
    Posted 17 years ago #

    You would have to add a plugin that does a string replace filter on the post title or body.

    Floating somewhere around here is a quick snippet for an untitled posts plugin/hack that I put up several months ago. You could use that as a guide, and then find the right filters/actions to tie into.

  3. mysorehead
    Member
    Posted 17 years ago #

    There is a link for a how to write a plugin with a basic example that does exactly what you are asking for. The author writes it during the screencast and explains how it works.

    http://txfx.net/files/wp-movies/001-your-first-wp-plugin.mov

    Richard

  4. dsader
    Member
    Posted 17 years ago #

    Cool movie, mysorehead.

    You probably have more than one word in mind to censor:

    <?php
    /*
    Plugin Name: Fix bad words.
    */
    
    function fix_bad_words($text) {
        $bad_words = array(
            'bad' => "%#$!%$",
            'bad word' => "%#$!%$",
            'worse word' => "%#$!%$",
            'very bad word' => "%#$!%$",
            'much more badder word' => "%#$!%$",
            'anything' => "%#$!%$",
            'really' => "%#$!%$",
        );
            foreach ($bad_words as $bad_word => $fix)
            $text = str_replace($bad_word, $fix, $text);
        return $text;
    }
    add_filter('the_title', 'fix_bad_words');
    add_filter('the_content', 'fix_bad_words');
    add_filter('comment_text', 'fix_bad_words');
    ?>
  5. lucky2
    Member
    Posted 17 years ago #

    Thanks to all! I think this may be the answer.

  6. drmiketemp
    Member
    Posted 17 years ago #

    Can you list some examples of very bad words please? I'm not sure I understand what the concept is.

  7. lunabyte
    Member
    Posted 17 years ago #

    Riiiiiiiiiiight....

    LOL

    You aren't "that" innocent, Doc.

  8. drmiketemp
    Member
    Posted 17 years ago #

    WHY WON'T ANYONE HELP ME?!?!?!?!?

  9. lunabyte
    Member
    Posted 17 years ago #

    <slap> lol

About this Topic