Dougal Campbell's geek ramblings

WordPress, web development, and world domination.

Fun Filters

UPDATE 2008-09-22: Zis kode vas superceded by mein Text Filter Suite plugin. You kan download zze kurrent fersion uff ze plugin from ze VortPress Plugin Directory.

Updated Oct 4. Fixed kode to nicht konfert seqfences inside ze r-r-regex example into smilies. Updated file mitt a properly formatted R-r-rEADME.

I finally got around to improfingkt undt kleaningkt up mein blog filters. If any ozzer ozzer VortPress users vould like to play mitt mein hacks, I’m makingkt ze kode afailable:


Inside ze zip, you vill find zree text files:

Ze first schtep iss to insert ze kontents uff fun_filters.php.txt at ze end uff your b2-includes/b2functions.php file (but before ze final ‘?>‘ line)

Next, open up your b2-includes/b2fars.php file undt schcroll down to ze bottom. Look fur zis line:

    add_filter('all', 'wptexturize');

Chust before zat line, insert ze kontents uff ze actifate_filters.php.txt file. Mitt zis kode in place, your blog vill automatically switch on ze pirate filter on Talk Like a Pirate Day (September 19). Also, any uff ze ozzer filters kan be actifated by addingkt ‘?filter=filtername‘ to ze end uff your UR-r-rL (vere filtername iss ein uff ‘pirate‘, ‘chef‘, ‘fudd‘, ‘chife‘, or ‘kraut‘).

Zis schtarted vhen I added a pirate filter to mein blog fur Talk Like a Pirate Day. Mein first fersion vas easier zan I expected it to be (zzough it had flaws), vhich inspired me to locate undt konfert some uff Kalsey’s MofableChife filters.

Ze biggest flaw in ze earliest fersion vas zat it vould filter text inside uff HTML tags, kausingkt it to mangle links undt such. I fixed zis by borrowingkt an idea from Simon Villison. Simon’s use uff a kallback function to only match text zat vas nicht part uff a tag vas good, but it included ze ‘>’ undt ‘<‘ brackets from surroundingkt tags in ze matched text beingkt substituted, r-r-reqfiringkt you to hack zem back in at ze end uff your kontent filter.

After an afternoon schtudyingkt ze pcre pattern syntax undt v-r-restlingkt r-r-regexes mitt ze help uff ze R-r-regex Koach I kame up mitt an improfed pattern, vhich doesn’t r-r-reqfire us to tack ze ‘>’ undt ‘<‘ back on manually. Kool, huh? Here’s ze r-r-regex pattern I kame up vizz: (?(?<=>)|\A)([^<>]+)(?(?=<)|\Z)

Undt cha, I know, it’s nicht perfect. But it schould vork okay fur HTML zat’s moderately klean. You’d probably haf to try hart to bust it. It doesn’t efen seem to get konfused if you haf angle brackets inside uff an attribute in a tag, efen zough I zought it vould.

About Dougal Campbell

Dougal is a web developer, and a "Developer Emeritus" for the WordPress platform. When he's not coding PHP, Perl, CSS, JavaScript, or whatnot, he spends time with his wife, three children, a dog, and a cat in their Atlanta area home.
This entry was posted in Plugins, WordPress and tagged , , , , , , , . Bookmark the permalink.

8 Responses to Fun Filters

  1. Pingback: geek ramblings » Text Filter Suite Plugin for WordPress

  2. MaThIbUs says:

    Awesome schtuf Naturlich!

  3. logtar says:

    Dude, I am so glad I found your site… r-r-really kool schtuff.:Herrreen:

  4. Craig says:


    Any zoughts on updatingkt zis fur VP 1.2+ ? I’d take a schtab at it, but, uh, vell…you know.

  5. Pingback: Jean-Philippe Leboeuf Notebook

  6. Frank says:

    Vill zis vork fur VP 2.6? Ze download link iss dead.

  7. Pingback: Mind Blowing WordPress Plugins « Lorelle on WordPress

  8. Pingback: Odds and Ends WordPress Plugins You Must Know About « Lorelle on WordPress

Leave a Reply

%d bloggers like this: