<?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>Tim Van Wassenhove &#187; WordPress</title>
	<atom:link href="http://www.timvw.be/category/information-technology/php/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.timvw.be</link>
	<description>The journey of a thousand miles begins with one step.</description>
	<lastBuildDate>Thu, 29 Jul 2010 17:07:31 +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>WordPress: Import Blogroll from Sage</title>
		<link>http://www.timvw.be/wordpress-import-blogroll-from-sage/</link>
		<comments>http://www.timvw.be/wordpress-import-blogroll-from-sage/#comments</comments>
		<pubDate>Sat, 25 Aug 2007 20:54:15 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.timvw.be/wordpress-import-blogroll-from-sage/</guid>
		<description><![CDATA[Earlier today i exported the list with blogs i read from Sage and tried to import them into WordPress. Although all the entries had been processed but none of them appeared. Apparently you have to rename the xmlUrl attribute to htmlUrl in the OPML file. With Vim that&#8217;s as simple as &#8220;:%s/xmlUrl/htmlUrl/g&#8221;. Anyway, feel free [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today i exported the list with blogs i read from <a href="http://sage.mozdev.org/">Sage</a> and tried to import them into <a href="http://wordpress.org">WordPress</a>. Although all the entries had been processed but none of them appeared. Apparently you have to rename the xmlUrl attribute to htmlUrl in the <a href="http://en.wikipedia.org/wiki/OPML">OPML</a> file. With Vim that&#8217;s as simple as &#8220;:%s/xmlUrl/htmlUrl/g&#8221;.</p>
<p>Anyway, feel free to see if you find anything interesting in the <a href="http://www.timvw.be/wp-links-opml.php">list of blogs i&#8217;m reading</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/wordpress-import-blogroll-from-sage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internationalizing strings with variables</title>
		<link>http://www.timvw.be/internationalizing-strings-with-variables/</link>
		<comments>http://www.timvw.be/internationalizing-strings-with-variables/#comments</comments>
		<pubDate>Sun, 19 Mar 2006 00:47:03 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.timvw.be/internationalizing-strings-with-variables/</guid>
		<description><![CDATA[Yesterday i wrote that you can use __($string, $domain) and _e($string, $domain) to internationalize a string with WordPress. I forgot to mention that if you use sprintf you can handle strings with variables too. An example: echo sprintf(__('There are %d monkeys in the %s'), $domain), $number, $location);]]></description>
			<content:encoded><![CDATA[<p>Yesterday i wrote that you can use __($string, $domain) and _e($string, $domain) to internationalize a string with <a href="http://www.wordpress.org">WordPress</a>. I forgot to mention that if you use <a href="http://www.php.net/sprintf">sprintf</a> you can handle strings with variables too. An example:</p>
<pre class="brush: php;">
echo sprintf(__('There are %d monkeys in the %s'), $domain), $number, $location);
</pre>]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/internationalizing-strings-with-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding support for localization to a WordPress plugin</title>
		<link>http://www.timvw.be/adding-support-for-localization-to-a-wordpress-plugin/</link>
		<comments>http://www.timvw.be/adding-support-for-localization-to-a-wordpress-plugin/#comments</comments>
		<pubDate>Sun, 19 Mar 2006 00:34:29 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.timvw.be/adding-support-for-localization-to-a-wordpress-plugin/</guid>
		<description><![CDATA[WordPress uses GNU gettext, as explained in Translating WordPress and Writing a Plugin, for localization. I decided that my plugins should support l10n too. Here is how i realised it: I started with defining the WPLANG constant in my wp-config.php: define ('WPLANG', 'en_EN'); Then i changed the beginning of my localized plugin as following: &#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress uses <a href="http://www.gnu.org/software/gettext/">GNU gettext</a>, as explained in <a href="http://codex.wordpress.org/Localizing_WordPress">Translating WordPress</a> and <a href="http://codex.wordpress.org/Writing_a_Plugin">Writing a Plugin</a>, for <a href="http://en.wikipedia.org/wiki/Software_localization">localization</a>. I decided that my plugins should support l10n too. Here is how i realised it:</p>

<p>I started with defining the WPLANG constant in my wp-config.php:</p>
<pre class="brush: php;">define ('WPLANG', 'en_EN');</pre>

<p>Then i changed the beginning of my localized plugin as following:</p>
<pre class="brush: php;">&lt;?php
/*
Plugin Name: WP-SpamFilter
Version: 0.4
Plugin URI: http://timvw.madoka.be/?p=533
Description: Mark the new comment as spam if the sender is in the spammers list.
Author: Tim Van Wassenhove &lt;timvw@users.sourceforge.net&gt;
Author URI: http://timvw.be
*/

// If this function does not exist it means that the file is accessed directly.
// Accessing this file directly is not allowed.
if (!function_exists('load_plugin_textdomain')) {
  exit;
}

load_plugin_textdomain('wp_spamfilter', 'wp-content/plugins/wp-spamfilter');
</pre>

<p>In wp-includes/wp-l10n.php you see that the result of this call is that the locale and the path are used to determine the mo-file to be loaded. Because this function uses ABSPATH it&#8217;s impossible to use dirname(__FILE__) as path parameter <img src='http://www.timvw.be/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>

<p>The _e($string, $domain) function echos a localized string and the __($string, $domain) function returns a localized string that you can use in function calls etc&#8230; Below you can see an example of the original version and the updated version with localization support: </p>
<pre class="brush: php;">
&lt;h2&gt;some string&lt;/h2&gt;
&lt;?php echo('some other string'); ?&gt;
</pre>

<pre class="brush: php;">
&lt;h2&gt;&lt;?php _e('some string', 'wp_spamfilter'); ?&gt;&lt;/h2&gt;
&lt;?php echo(__('some other string', 'wp_spamfilter')); ?&gt;
</pre>

<p>Then i used xgettext to extract all the strings that should be localized into wp_spamfilter-en_EN.po:</p>

xgettext &#8211;keyword=__ &#8211;keyword=_e &#8211;default-domain=wordpress &#8211;language=php *.php &#8211;output=wp_spamfilter-en_EN.po


<p>After that i editted the po file and i compiled a mo file with it using msgfmt:</p>

msgfmt wp_spamfilter-en_EN.po -o wp_spamfilter-en_EN.mo


<p>Once i had made sure that wp_spamfilter-en_EN.mo was readable by my webserver i was ready.</p>]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/adding-support-for-localization-to-a-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plugin template for WordPress</title>
		<link>http://www.timvw.be/plugin-template-for-wordpress/</link>
		<comments>http://www.timvw.be/plugin-template-for-wordpress/#comments</comments>
		<pubDate>Sun, 19 Mar 2006 00:32:19 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.timvw.be/plugin-template-for-wordpress/</guid>
		<description><![CDATA[Today i&#8217;ve been cleaning up my code. All my plugins live in a directory %plugin_name% under the wp-content/plugins directory. Here is the code for %plugin_name%/%plugin_name%.php: &#60;?php /* Plugin Name: %plugin_name% Version: %plugin_version% Plugin URI: %plugin_uri% Description: %plugin_description% Author: %plugin_author_name% &#60;%plugin_author_mail%&#62; Author URI: %plugin_author_uri% */ // Direct access is not allowed. if (!function_exists('load_plugin_textdomain')) { exit; } [...]]]></description>
			<content:encoded><![CDATA[<p>Today i&#8217;ve been cleaning up my code. All my plugins live in a directory %plugin_name% under the wp-content/plugins directory. Here is the code for %plugin_name%/%plugin_name%.php:</p>
<pre class="brush: php;">&lt;?php
/*
Plugin Name: %plugin_name%
Version: %plugin_version%
Plugin URI: %plugin_uri%
Description: %plugin_description%
Author: %plugin_author_name% &lt;%plugin_author_mail%&gt;
Author URI: %plugin_author_uri%
*/

// Direct access is not allowed.
if (!function_exists('load_plugin_textdomain')) {
  exit;
} else {
  require('%plugin_name%.php');
  $plugin_name = substr(basename(__FILE__), 0, -4);

  // You can add optional parameters to the constructor, eg: the wpdb instance.
  $%plugin_class% = new %plugin_class%($plugin_name);
}
?&gt;</pre>

<p>Now it&#8217;s time to implement the %plugin_class%. Here is the template for %plugin_name%/%plugin_class%.php:</p>
<pre class="brush: php;">&lt;?php

class %plugin_class% {
  var $_plugin_name;

  var $_localization_domain;
  var $_localization_path;

  function %plugin_class%($plugin_name = '%plugin_name%') {
    $this-&gt;_plugin_name = $plugin_name;

    $this-&gt;_localization_domain = $plugin_name;
    $this-&gt;_localization_path = 'wp-content/plugins/' . $plugin_name;

    // You can add additional hooks and filters here.
    add_action('activate_' . $plugin_name . '/' . $plugin_name . '.php', array(&amp;$this, 'OnActivation'));
    add_action('admin_menu', array(&amp;$this, 'OnAdminMenu'));
}

  function OnAdminMenu() {
    load_plugin_textdomain($this-&gt;_localization_domain, $this-&gt;_localization_path);
    add_options_page(__('%plugin_name% Options', $this-&gt;_localization_domain), __('%plugin_name%', $this-&gt;_localization_domain), 'manage_options',$this-&gt;_plugin_name . '/' . $this-&gt;_plugin_name . '-options.php', array(&amp;$this, 'OnDisplayOptions'));
  }

  function OnDisplayOptions() {
    $%plugin_class% = &quot;&quot;;
    require( dirname(__FILE__) . '/' . $this-&gt;_plugin_name . '-options.php');
  }

  function OnActivation() {
    // This code is executed when the plugin is activated.
    // I prepend all my option names with $this-&gt;_plugin_name.
    add_option($this-&gt;_plugin_name . '_somevar', 'foo');
  }
}
?&gt;</pre>

<p>The code above requires that you create a %plugin_name%/%plugin_name%-options.php file to administrate the options. Here is the template for that file:</p>
<pre class="brush: php;">
&lt;?php
// Direct access is not allowed.
if (!isset($%plugin_class%)) {
  exit;
}                                                                                                                     

load_plugin_textdomain($%plugin_class%-&gt;_localization_domain, $%plugin_class%-&gt;_localization_path);

// Handle post action.
if ($_POST['stage'] == 'process') {
  // All the names of form variables start with %plugin_class%_plugin_name.
  if (isset($_POST[$%plugin_class%-&gt;_plugin_name . '_somevar'])) {
    // Do processing here.
  }
}

?&gt;
&lt;form method=&quot;post&quot; action=&quot;&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;stage&quot; value=&quot;process&quot;/&gt;
  &lt;input type=&quot;text&quot; name=&quot;&lt;?php echo $%plugin_class%-&gt;_plugin_name . '_somevar'; ?&gt;&quot;/&gt;
  &lt;input type=&quot;submit&quot; value=&quot;&lt;?php _e('Submit', $%plugin_class%-&gt;_localization_domain); ?&gt;&quot;/&gt;
&lt;/form&gt;
</pre>

<p>The only thing that we still have to do is generate a po file with xgettext, translate it and compile a %plugin_name%/%plugin_name%-en_EN.mo file.</p>]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/plugin-template-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding an action when your plugin is activated</title>
		<link>http://www.timvw.be/adding-an-action-when-your-plugin-is-activated/</link>
		<comments>http://www.timvw.be/adding-an-action-when-your-plugin-is-activated/#comments</comments>
		<pubDate>Wed, 15 Mar 2006 00:47:58 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.timvw.be/adding-an-action-when-your-plugin-is-activated/</guid>
		<description><![CDATA[The WordPress documentation says that you have to call add_action(&#8216;activate_pluginurl&#8217;, &#8216;somefunction&#8217;) to trigger somefunction when your plugin is activated. Unfortunately i couldn&#8217;t find with what pluginurl should be replaced. After a bit of experimenting i&#8217;ve found that in wp-admin/plugins.php the following is called when a plugin is activated: do_action('activate_' . trim( $_GET['plugin'] )); So it [...]]]></description>
			<content:encoded><![CDATA[<p>The WordPress documentation says that you have to call add_action(&#8216;activate_pluginurl&#8217;, &#8216;somefunction&#8217;) to trigger somefunction when your plugin is activated. Unfortunately i couldn&#8217;t find with what pluginurl should be replaced. After a bit of experimenting i&#8217;ve found that in wp-admin/plugins.php the following is called when a plugin is activated:</p>

<pre class="brush: php;">
do_action('activate_' . trim( $_GET['plugin'] ));
</pre>

<p>So it appears that you simply have to use the path of your plugin relative to /wp-content/plugins. Eg: you have a plugin in /wp-content/plugins/wp-spamfilter/wp-spamfilter.php then you have to call add_action as following:</p>

<pre class="brush: php;">
add_action('activate_wp-spamfilter/wp-spamfilter.php', 'somefunction');
</pre>]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/adding-an-action-when-your-plugin-is-activated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
