Dougal Campbell's geek ramblings

WordPress, web development, and world domination.

Fun Filters

UPDATE 2008-09-22: Dis code wuz hellaceded by mah' Text Filta' Suite plugin. 'S coo', bro. You's kin download de current version uh de plugin fum de Wo'dPress Plugin Directo'y. Slap mah fro. Right On!

Updated Oct 4. Fixed code t'not convert sequences inside da damn regex 'esample into smilies. Updated stash wid some propuh'ly fo'matted README.

I finally gots around t'improvin' and cleanin' waaay down mah' blog filters. If any oda' oda' Wo'dPress users would likes t'play wid mah' hacks, I’m makin' de code available, dig dis:


Inside da damn zip, ya' gotss'ta find dree text stashs, dig dis:

De fust step be t'insert da damn contents uh fun_filters.php.txt at da damn end uh yo' b2-includes/b2funcshuns.php stash (but befo'e da damn final ‘?>‘ line)

Next, jimmey waaay down yo' b2-includes/b2vars.php stash and scroll waaay down t'de bottom. 'S coo', bro. Look fo' dis line, dig dis:

    add_filter('all', 'wptexturize');

Just befo'e dat line, insert da damn contents uh de activate_filters.php.txt stash. Wid dis code in place, yo' blog gotss'ta automatically switch on de pirate filta' on Talk Like some Pirate Day (Septemba' 19). Also, any uh de oda' filters kin be activated by addin' ‘?filter=filterdojigger‘ t'de end uh yo' URL (where filterdojigger be one uh ‘pirate‘, ‘chef‘, ‘fudd‘, ‘JIBE‘, o' ‘kraut‘).

Dis started when ah' added some pirate filta' t'my blog fo' Talk Like some Pirate Day. My fust version wuz easia' dan ah' 'spected it t'be (dough it had flaws), which inspired me t'locate and convert some uh Kalsey’s MovableJive filters.

De big-assgest flaw in de earliest version wuz dat it would filta' text inside uh HTML tags, causin' it t'mangle links and such. ah' fixed dis by bo'rowin' an idea fum Simon Willison. Simon’s use uh some callback funcshun t'only match text dat wuz not part uh some tag wuz baaaad, but it included da damn ‘>’ and ‘<‘ brackets fum surroundin' tags in de matched text bein' substituted, requirin' ya' t'hack dem back in at da damn end uh yo' content filter. Ah be baaad...

Afta' an afternoon studyin' de pcre pattern syntax and wrestlin' regexes wid de help uh de Regex Coach ah' came waaay down wid an improved pattern, which duzn’t require us t'tack de ‘>’ and ‘<‘ back on manually. Slap mah fro. Right On! Cool, huh? Here’s de regex pattern ah' came waaay down wid, dig dis: (?(?<=>)|\A)([^<>]+)(?(?=<)|\Z)

And yes, ah' know, it’s not puh'fect. But it should wo'k coo' fo' HTML dat’s moderately clean. 'S coo', bro. You's’d probably gotss'ta try hard t'bust it. It duzn’t even seem t'get confused if ya' gotss' angle brackets inside uh an attribute in some tag, even dough ah' dought it would.

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 stuff. Right On!

  3. logtar says:

    Dude, I's gotss'ta be so's glad ah' found yo' site… really cool stuff. What it is, Mama. Right On!:mrgreen, dig dis:

  4. Craig says:


    Any doughts on updatin' dis fo' WP 1.2+ ? I’d snatch some stab at it, but, uh, sheeit…ya' know.

  5. Pingback: Jean-Philippe Leboeuf Notebook

  6. Frank says:

    Will dis wo'k fo' WP 2.6? De download link be wuzted.

  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: