<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Xavier Llorà &#187; php</title>
	<atom:link href="http://www.xavierllora.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xavierllora.net</link>
	<description>A notebook about data-intensive computing, genetics-based machine learning, semantic-web technology, cloud computing,  and more.</description>
	<lastBuildDate>Thu, 15 Jul 2010 19:50:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A simple skeleton plugin for WordPress</title>
		<link>http://www.xavierllora.net/2008/07/03/a-simple-skeleton-plugin-for-wordpress/</link>
		<comments>http://www.xavierllora.net/2008/07/03/a-simple-skeleton-plugin-for-wordpress/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 04:02:14 +0000</pubDate>
		<dc:creator>Xavier</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[meandre]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[slideshare]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.xavierllora.net/?p=255</guid>
		<description><![CDATA[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. [...]


Related posts:<ol><li><a href='http://www.xavierllora.net/2007/04/10/wordpress-mu-plugin-to-render-math-using-latex-commands/' rel='bookmark' title='Permanent Link: WordPress MU plugin to render math using latex commands'>WordPress MU plugin to render math using latex commands</a></li>
<li><a href='http://www.xavierllora.net/2008/06/04/iphone-and-your-wordpress/' rel='bookmark' title='Permanent Link: iPhone and your WordPress'>iPhone and your WordPress</a></li>
<li><a href='http://www.xavierllora.net/2009/01/27/need-a-quick-form-on-your-wordpress-site/' rel='bookmark' title='Permanent Link: Need a quick form on your WordPress site?'>Need a quick form on your WordPress site?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Preparing for the upcoming <a href="http://seasr.org/meandre">Meandre</a> release, as part of the larger <a href="http://seasr.org">SEASR</a> on, I have been exploring a bit the inner machinery of <a href="http://wordpress.org/">WordPress</a> to create a simple plugin for the <a href="http://seasr.org">SEASR</a> site that could render <a href="http://seasr.org/meandre">Meandre</a> component and flow descriptions straight out of their  RDF desciptors. Actually, it turned out to be a breeze. After being a heavy user of <a href="http://wordpress.org/">WordPress</a> 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.</p>
<p>I looked into several <a href="http://wordpress.org/extend/plugins/">freely available plugins</a>, the one that got me going was a very simple one, the <a href="http://wordpress.org/extend/plugins/slideshare/">SlideShare plugin</a> by <a href="http://wordpress.org/extend/plugins/profile/joostdevalk">Joost de Valk</a>. The plugin transforms a formated tag into code that embed a flash player for <a href="http://www.slideshare.net/">SlideShare presentation</a>. 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 <code>[tag-mnemonic param1 param2]</code> and the plugin replaces it by just a HTML list of the two parameters.</p>
<pre class="brush: php">
 &lt;?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;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(&quot;SP_REGEXP&quot;, &quot;/\[tag-mnemonic ([[:print:]]+) ([[:print:]]+)\]/&quot;);
define(&quot;SP_TARGET&quot;, &quot;&lt;ul&gt;&lt;li&gt;###Param1###&lt;/li&gt;&lt;li&gt;###Param2###&lt;/li&gt;&lt;/ul&gt;&quot; );

function sp_plugin_callback($match)
{
	$output = SP_TARGET;
	$output = str_replace(&quot;###Param1###&quot;, $match[1], $output);
	$output = str_replace(&quot;###Param2###&quot;, $match[2], $output);
	return ($output);
}

function sp_plugin($content)
{
	return (preg_replace_callback(SP_REGEXP, &#039;sp_plugin_callback&#039;, $content));
}

add_filter(&#039;the_content&#039;, &#039;sp_plugin&#039;);
add_filter(&#039;comment_text&#039;, &#039;sp_plugin&#039;);

?&gt;
</pre>
<p>That means that if you write the tag <code>[tag-mnemonic http://foo.org http://example.org]</code>, the plugin will reformat the tag and inject the following html code</p>
<pre class="brush: html">
&lt;ul&gt;
&lt;li&gt;http://foo.org&lt;/li&gt;
&lt;li&gt;http://exampl.org&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>where the tag originally was. And that&#8217;s it! </p>
<p>One more thing. The only thing you may want to be aware is the filtering chain. The <code>add_filter</code> 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 <a href="http://codex.wordpress.org/Plugin_API#Hook_in_your_Filter">add_filter documentation</a>. It may save you some time, trust me <img src='http://www.xavierllora.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>PS: Joost had some comments on improving this simple plugin. Check the comments below</p>


<p>Related posts:<ol><li><a href='http://www.xavierllora.net/2007/04/10/wordpress-mu-plugin-to-render-math-using-latex-commands/' rel='bookmark' title='Permanent Link: WordPress MU plugin to render math using latex commands'>WordPress MU plugin to render math using latex commands</a></li>
<li><a href='http://www.xavierllora.net/2008/06/04/iphone-and-your-wordpress/' rel='bookmark' title='Permanent Link: iPhone and your WordPress'>iPhone and your WordPress</a></li>
<li><a href='http://www.xavierllora.net/2009/01/27/need-a-quick-form-on-your-wordpress-site/' rel='bookmark' title='Permanent Link: Need a quick form on your WordPress site?'>Need a quick form on your WordPress site?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.xavierllora.net/2008/07/03/a-simple-skeleton-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
