Mime Wordpress Plugin

IMPORTANT: This post has moved.

Wordpress is really cool.

But what if you want to have “richer” content? Not just the text you type, but some fancy HTML or PHP stuff? Even if you just want HTML come across exactly as you designed it, the filtering mechanism (wpautop in particular) gets in the way.

So I decided to write a plugin that basically leaves content alone. You just have to add a meta, ‘mime_type’ with value of ‘text/html’ and your post won’t be filtered by wpautop.

I called this plugin Mime because I thought this fits somehow, and also leaves some potential for further enhancement. Well, this plugin is so small I should have called it ‘Basic’ or something like that :) The real answer for the name is that I’m using Wordpress in a PHP MVC engine as the CMS, and this engine is really capable of recognizing different mime types and interpreting them at run-time. E.g., you could even implement some Smarty interpretation.

If you have any ideas about some really cool mime stuff for this plugin, please let me know.

Here it is:

<?php
/*
Plugin Name: Mime
Version: 1.0
Plugin URI: http://www.uberdose.com/journal/
Description: Switches wpautop off in cases where the post content is pure HTML.
Author: Dirk Zimmermann
Author URI: http://www.uberdose.com/journal/archives/2004/07/17/mime-wordpress-plugin/
*/

function mime($text) {
global $post_meta_cache, $post;
if (is_array($post_meta_cache[$post->ID]['mime_type'])) {
$mimeType = $post_meta_cache[$post->ID]['mime_type'][0];
}
if (isset($mimeType) && $mimeType == 'text/html') {
return $text;
} else {
return wpautop($text);
}
}

remove_filter('the_content', 'wpautop');

add_filter('the_content', 'mime', 6);

?>

11 Responses to “Mime Wordpress Plugin”

Leave a Reply


uberdose 2.0

L-l-look at you, hacker.