Preparing for the upcoming Meandre release, as part of the larger SEASR on, I have been exploring a bit the inner machinery of WordPress to create a simple plugin for the SEASR site that could render Meandre component and flow descriptions straight out of their RDF desciptors. Actually, it turned out to be a breeze. After being a heavy user of WordPress in several project for few years now, its extensibility keeps sparking new possibilities in my mind every time I look into any of its facets. Anyway, I am rambling. Back to the point. To hit the ground running, I started by creating a simple generic plugin that would replace a tag with parameters for something else.
I looked into several freely available plugins, the one that got me going was a very simple one, the SlideShare plugin by Joost de Valk. The plugin transforms a formated tag into code that embed a flash player for SlideShare presentation. Below, I reproduce the skeleton of a plugin that will replace the tags in your post/pages/comments for whatever you like. A tag takes the form [tag-mnemonic param1 param2] and the plugin replaces it by just a HTML list of the two parameters.
<?php
/*
Plugin Name: Simple Plugin
Plugin URI: http://host.org/
Description: Replaces a tag for a list.
Version: 0.1
Author: Xavier Llor&amp;amp;amp;amp;amp;amp;amp;agrave;
Author URI: http://www.xavierllora.net
Based on SlideShare plugin (http://wordpress.org/extend/plugins/slideshare/)
Installation: copy simple-plugin.php to the wp-content/plugins directory of
your Wordpress installation, then activate the plugin. Use the following syntax
for your tag
[tag-mnemonic Param1 Param2]
When the plugin is active, the tag will be replaced by a simple HTML list
containing the parameter values.
*/
define("SP_REGEXP", "/\[tag-mnemonic ([[:print:]]+) ([[:print:]]+)\]/");
define("SP_TARGET", "<ul><li>###Param1###</li><li>###Param2###</li></ul>" );
function sp_plugin_callback($match)
{
$output = SP_TARGET;
$output = str_replace("###Param1###", $match[1], $output);
$output = str_replace("###Param2###", $match[2], $output);
return ($output);
}
function sp_plugin($content)
{
return (preg_replace_callback(SP_REGEXP, 'sp_plugin_callback', $content));
}
add_filter('the_content', 'sp_plugin');
add_filter('comment_text', 'sp_plugin');
?>
That means that if you write the tag [tag-mnemonic http://foo.org http://example.org], the plugin will reformat the tag and inject the following html code
<ul> <li>http://foo.org</li> <li>http://exampl.org</li> </ul>
where the tag originally was. And that’s it!
One more thing. The only thing you may want to be aware is the filtering chain. The add_filter has a third numeric parameter. When you have multiple plugins that rely on filters to do their job, sometimes you may need to force a certain order of execution to avoid stepping on each others toes. If that is your case, you better check the add_filter documentation. It may save you some time, trust me
PS: Joost had some comments on improving this simple plugin. Check the comments below

