<?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>Thijs Lensselink&#039;s Blog &#187; wordpress</title>
	<atom:link href="http://lenss.nl/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://lenss.nl</link>
	<description>Webdevelopment and stuff...</description>
	<lastBuildDate>Mon, 06 Feb 2012 20:37:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Writing a simple WordPress plugin</title>
		<link>http://lenss.nl/2011/03/writing-a-simple-wordpress-plugin/</link>
		<comments>http://lenss.nl/2011/03/writing-a-simple-wordpress-plugin/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 23:07:38 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[DWOTD]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=1173</guid>
		<description><![CDATA[In the spirit of Ideas for March i should really be blogging more. Somehow i just can&#8217;t think of anything interesting at the moment. Will give it a shot anyway. Last week i created my first ever WordPress plugin. It&#8217;s an extremely simple one. And for sure nothing new or special. But it was a [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: left; margin: 10px;" src="http://lenss.nl/wp-content/uploads/2011/03/wordpress.jpg" alt="" title="wordpress" width="150" height="150" class="alignleft size-full wp-image-1191" /> In the spirit of <a href="http://lenss.nl/2011/03/ideas-of-march/">Ideas for March</a> i should really be blogging more. Somehow i just can&#8217;t think of anything interesting at the moment. Will give it a shot anyway.</p>
<p>Last week i created my first ever <a href="http://wordpress.org/">WordPress</a> <a href="http://codex.wordpress.org/Writing_a_Plugin">plugin</a>. It&#8217;s an extremely simple one. And for sure nothing new or special. But it was a fun experience. I have always dreaded the WP code base. The mixture of OO and procedural programming just looks plain ugly to me. But i don&#8217;t want to be bash WP. I use it myself. So i took the dive and spend a few hours hacking and <a href="http://codex.wordpress.org/Plugin_API">reading</a>. And the result is my <strong>DWOTD</strong> (Dutch Word Of The Day) plugin.</p>
<p>To get some inspiration for this i took a look at some plugin code available on the internet. This gave me a basic understanding of how the plugin system works. Together with the docs writing a plugin wasn&#8217;t that hard. The code that i saw however was pretty bad. And i wanted something that at least looked better then all the global statements swarming around. So i created a small OO wrapper for the plugin. The basic plugin structure looks something like this</p>
<blockquote><p>
&#8211; plugin<br />
&#8212;&#8211; css<br />
&#8212;&#8212;&#8212;- dwotd.css<br />
&#8212;&#8211; lib<br />
&#8212;&#8212;&#8212;- Dwotd.php<br />
&#8212;&#8212;&#8212;- Widget.php<br />
&#8212;&#8211; template<br />
&#8212;&#8212;&#8212;- Widget.php<br />
&#8211; dwotd.php
</p></blockquote>
<p>The file in the root is the bootstrap file. It includes the main plugin class and registers the widget class. The two files in lib contain the plugin and Widget classes. The rest is self explanatory i think.</p>
<p>The first lines of the bootstrap file contain a comment block that is used by WP to show some more information about the plugin inside the admin. </p>
<pre name="code" class="php">
/*
Plugin Name: DWOTD
Plugin URI: http://lenss.nl/projects/dwotd-plugin/
Description: Dutch Word Of The Day including English translation
Author: Thijs Lensselink
Author URI: http://lenss.nl/
Version: 1.2
*/
</pre>
<p>Then the plugin class file is loaded and the a plugin object instantiated.</p>
<pre name="code" class="php">
require_once(dirname(__FILE__).'/lib/Dwotd.php');

$DWOTD = new DWOTD_Plugin();
wp_register_style('dwotd', "{$DWOTD->getPluginDir()}/css/dwotd.css");
wp_enqueue_style('dwotd', "{$DWOTD->getPluginDir()}/css/dwotd.css");
</pre>
<p>If the logged in user is a admin hooks for <em>installing</em> and <em>uninstalling</em> the plugin will be activated.</p>
<pre name="code" class="php">
if ( is_admin() ) {
	register_activation_hook(__FILE__, array($DWOTD, 'install'));
	register_deactivation_hook(__FILE__, array($DWOTD, 'uninstall'));
}
</pre>
<p>And finally register the Widget class</p>
<pre name="code" class="php">
add_action('widgets_init', create_function('', 'return register_widget("DWOTD_Widget");'));
</pre>
<p>The Widget class is a simple wrapper around the plugin class. It basically instantiates the Plugin class and after that the <em>widget()</em> method gets called. This method calls the Plugin and finally renders a view for the widget box.</p>
<pre name="code" class="php">
class DWOTD_Widget extends WP_Widget
{
	protected $_dwotd;

	public function DWOTD_Widget()
	{
		$this->_dwotd = new DWOTD_Plugin();
		parent::WP_Widget(false, $name = 'DWOTD Plugin');
	}

	public function widget($args, $instance)
	{
		$result = $this->_dwotd->getFromCache();
		if (!$result || $result->used_on != date('Y-m-d')) {
			try {
				$result = $this->_dwotd->fetchRandomWord();
				$this->_dwotd->writeToCache($result);
			} catch (Exception $e) {
				return new WP_Error('broke', __($e->getMessage()));
			}
		}

		$this->_renderView($result);
	}

	protected function _renderView($data)
	{
		ob_start();
		include $this->_dwotd->getTemplate();
		ob_get_contents();
	}

	public function update($new_instance, $old_instance)
	{
		$instance = $old_instance;
		return $instance;
	}
}
</pre>
<p>All real work is done inside the the Plugin class. This has all methods for talking to the database instance. But also contains the <a href="http://codex.wordpress.org/Plugin_API">hooks</a> for the WP install and uninstall actions. Some of the contents of this method are listed below.</p>
<pre name="code" class="php">
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
require_once(dirname(__FILE__).'/Widget.php');

Class DWOTD_Plugin
{
	public function __construct()
	{
		global $wpdb, $table_prefix;
                // set some class vars and include some files
	}

	public function install()
	{
                // create database and insert data
		add_option('dwotd_quote','1');
	}	

	public function uninstall()
	{
		$this->_dbh->query("DROP TABLE IF EXISTS `{$this->_dbName}`");
		delete_option('dwotd_quote');
	}

	public function getPluginDir()
	{
		return $this->_wpContent.'/plugins/dwotd';
	}
}
</pre>
<p>The code is just a small part of the real code. Which you can download <a href="http://lenss.nl/projects/dwotd-plugin/dwotd.tar.gz">here</a>. After that it&#8217;s quite easy. Create a folder for the plugin in <em>wp-content/plugins</em> and copy the files there. Enable it from the plugin manager and enable it in the widget menu (which didn&#8217;t work for me because my theme has no sidebar.. well not the wp one :)). So i had to use a manual approach.</p>
<p>After copying the files to the plugin folder login to <em>wp-admin</em> and browse to <em>Plugins/Plugins</em>. Search for the plugin and click activate. </p>
<p><a href="http://lenss.nl/wp-content/uploads/2011/03/widget-install.png"><img src="http://lenss.nl/wp-content/uploads/2011/03/widget-install-300x38.png" alt="" title="widget-install" width="300" height="38" class="alignleft size-medium wp-image-1186" /></a></p>
<p>Enabling the widget from the admin panel is easy. Browse to <em>Appearance/Widgets</em>. And drag the widget from the left to the sidebar panel on the right.</p>
<p><a href="http://lenss.nl/wp-content/uploads/2011/03/widget-drag.png"><img src="http://lenss.nl/wp-content/uploads/2011/03/widget-drag-300x68.png" alt="" title="widget-drag" width="300" height="68" class="alignleft size-medium wp-image-1185" /></a><br />
<a href="http://lenss.nl/wp-content/uploads/2011/03/widget-sidebar.png"><img src="http://lenss.nl/wp-content/uploads/2011/03/widget-sidebar.png" alt="" title="widget-sidebar" width="300" height="171" class="alignleft size-full wp-image-1187" /></a></p>
<p>Enabling it the manual way is also easy. But required a bit more work. For this to work the correct theme file needs to be edited somewhere in <em>wp-content/themes</em>. And the following code needs to be added in the spot the widget should appear.</p>
<pre name="code" class="php">
$args = array ( 'title' => '' );
$instance = array ( 'title' => 'DWOTD', 'number' => 1 );
$widget = new DWOTD_Widget();
$widget->widget($args,$instance);
</pre>
<p>That&#8217;s all. The result can be viewed on the right top side. I build the plugin for fun and use on an Intranet. So don&#8217;t go blaming me if it breaks something. Besides that everybody is free to do with the code as they please.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2011/03/writing-a-simple-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A new look for lenss.nl</title>
		<link>http://lenss.nl/2010/04/a-new-look-for-lenss-nl/</link>
		<comments>http://lenss.nl/2010/04/a-new-look-for-lenss-nl/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 19:17:30 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[/home]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=729</guid>
		<description><![CDATA[This long Easter weekend gave me some time to create a new theme for this blog. So after a day of work this is the result. I was a bit tired of the dark unreadable format. At the moment i am still tweaking here and there but it looks fine!]]></description>
			<content:encoded><![CDATA[<p>This long Easter weekend gave me some time to create a new theme for this blog. So after a day of work this is the result. I was a bit tired of the dark unreadable format. At the moment i am still tweaking here and there but it looks fine!</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/04/a-new-look-for-lenss-nl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing wp-e-commerce for iDEAL payments</title>
		<link>http://lenss.nl/2010/01/fixing-wp-e-commerce-for-ideal-payments/</link>
		<comments>http://lenss.nl/2010/01/fixing-wp-e-commerce-for-ideal-payments/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 15:03:02 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[iDEAL]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp-e-commerce]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=669</guid>
		<description><![CDATA[Last Friday a friend approached me with a problem he was having. He was trying to setup a small webshop in a existing WordPress site. For the webshop he was using a plug-in called wp-e-commerce. He chose this plug-in because it is one of few that supports iDEAL payments. Because this shop only serves Holland [...]]]></description>
			<content:encoded><![CDATA[<p>Last Friday a friend approached me with a problem he was having. He was trying to setup a small webshop in a existing WordPress site. For the webshop he was using a plug-in called <a href="http://0x.vc/a">wp-e-commerce</a>. He chose this plug-in because it is one of few that supports <a href="http://0x.vc/b">iDEAL</a> payments. Because this shop only serves Holland the only payment option they need is iDEAL.</p>
<p>The iDEAL plug-in seemed to function properly. But the bank portal didn&#8217;t respond as expected. The first error i spotted was the mis configured referrer. The error code for this was.</p>
<blockquote><p>unknown order/0/r</p></blockquote>
<p>This didn&#8217;t solve the problem though. The message change from the previous to</p>
<blockquote><p>unknown order/1/s</p></blockquote>
<p>So i spend the next hours reading the manual he got from his bank. And came to the conclusion they do it just a bit different then for what this plug-in was written. The bank expects a hash to be send along each order made. This hash is build up from parts of the order and a secret string. This combined is hashed with the <a href="http://0x.vc/c">SHA-1</a> algorithm And added to the form as a hidden field. I wrote a small function to create hash and changed a few other small things in the order form.</p>
<p>The original form looks like this:</p>
<pre name="code" class="html">
&lt;script type="text/javascript">
var Amount = <?php echo $amount; ?>;
var PSPID = "<?php echo get_option('ideal_id');?>";
var AM;
if (isNaN(Amount)) {
	alert("Amount not a number: " + Amount + " !");
	AM = "";
} else {
	AM = Math.round(parseFloat(Amount)*100);
}
&lt;/script>
&lt;form method='post' action='<?php echo $submiturl;?>' id='ideal_form' name='ideal_form'>
&lt;script type="text/javascript">
document.write("
<input type=\"hidden\" NAME=\"PSPID\" value=\"" + PSPID + "\" />");
document.write("
<input type=\"hidden\" NAME=\"amount\" value=\"" + AM + "\" />");
&lt;/script>
&lt;INPUT TYPE="hidden" NAME="SHASign" VALUE="4FF8C2FB03B0AA45EA5DE9503AEACB6B603DCFCC">
&lt;input type="hidden" NAME="orderID" value="<?php echo $purchase_log[0]['id'];?>" />
&lt;input type="hidden" name="currency" value="<?php echo get_option('ideal_currency');?>" />
&lt;input type="hidden" name="language" value="<?php echo get_option('ideal_language');?>" />
&lt;input type="hidden" name="accepturl" value="<?php echo get_option('product_list_url');?>">
&lt;input type="hidden" name="cancelurl" value="<?php echo get_option('shopping_cart_url');?>">
&lt;!--customer information starts-->
&lt;input type="hidden" name="CN" value="<?=$name;?>">
&lt;input type="hidden" name="EMAIL" value="<?=$email;?>">
&lt;input type="hidden" name="ownerZIP" value="<?=$postcode;?>">
&lt;input type="hidden" name="owneraddress" value="<?=$address;?>">
&lt;input type="hidden" name="ownercty" value="<?=$country;?>">
&lt;input type="hidden" name="ownertown" value="<?=$city;?>">
&lt;input type="hidden" name="ownertelno" value="<?=$phone;?>">
&lt;!--customer information ends-->
&lt;input type="hidden" name="PM" value="iDEAL" />
</pre>
<p>I didn&#8217;t really understand why some values were written by JavaScript. So i removed the JavaScript lines and added the fields to the form. And after adding the hash function statement it looks like this.</p>
<pre name="code" class="html">
&lt;form method='post' action='<?php echo $submiturl;?>' id='ideal_form' name='ideal_form'>

&lt;input type="hidden" NAME="PSPID" value="<?php echo get_option('ideal_id');?>" />
&lt;input type="hidden" NAME="orderID" value="<?php echo $purchase_log[0]['id'];?>" />
&lt;input type="hidden" NAME="amount" value="<?php echo ($amount*100); ?>" />
&lt;input type="hidden" name="currency" value="<?php echo get_option('ideal_currency');?>" />
&lt;input type="hidden" name="language" value="<?php echo get_option('ideal_language');?>" />
&lt;input type="hidden" name="accepturl" value="<?php echo get_option('product_list_url');?>">
&lt;input type="hidden" name="cancelurl" value="<?php echo get_option('shopping_cart_url');?>">
&lt;!--customer information starts-->
&lt;input type="hidden" name="CN" value="<?=$name;?>">
&lt;input type="hidden" name="EMAIL" value="<?=$email;?>">
&lt;input type="hidden" name="ownerZIP" value="<?=$postcode;?>">
&lt;input type="hidden" name="owneraddress" value="<?=$address;?>">
&lt;input type="hidden" name="ownercty" value="<?=$country;?>">
&lt;input type="hidden" name="ownertown" value="<?=$city;?>">
&lt;input type="hidden" name="ownertelno" value="<?=$phone;?>">
&lt;!--customer information ends-->
&lt;input type="hidden" name="PM" value="iDEAL" />
</pre>
<pre name="code" class="php">
echo createSHA1Hash(array(
		$purchase_log[0]['id'],
		($amount*100),
		get_option('ideal_currency'),
		get_option('ideal_id'),
		'[SHA1-IN-HASH]'
	));
</pre>
<pre name="code" class="php">
&lt;/form>
</pre>
<p>The function i can be placed anywhere in the page. Or a include file. Here&#8217;s the code. The only thing that has to be done is replace <strong>[SHA1-IN-HASH]</strong> with the Hash configured in the bank&#8217;s ideal admin.</p>
<pre name="code" class="php">
function createSHA1Hash($hashOptions) {
        $str = implode('', $hashOptions);

        return '
<input name="SHASign" type="hidden" value="' . sha1($str) . '" />';
    }
</pre>
<p>While doing some searches i noticed there are more people having issues with this plug-in. So maybe this will save somebody a bit of time.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/01/fixing-wp-e-commerce-for-ideal-payments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress and NO-WWW rewrite</title>
		<link>http://lenss.nl/2009/03/wordpress-and-no-www-rewrite/</link>
		<comments>http://lenss.nl/2009/03/wordpress-and-no-www-rewrite/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:10:37 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[no-www]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=402</guid>
		<description><![CDATA[On almost all of my domains i rewrite the WWW sub domain to the no-WWW version. This however went wrong on my own site. And i didn&#8217;t even notice it. My friend Alex pointed out that he couldn&#8217;t post any comment to the site anymore. So what went wrong? Normally i use the following lines [...]]]></description>
			<content:encoded><![CDATA[<p>On almost all of my domains i rewrite the WWW sub domain to the <a href="http://no-www.org/">no-WWW</a> version. This however went wrong on my own site. And i didn&#8217;t even notice it. My friend <a href="http://www.lexternet.nl/">Alex</a> pointed out that he couldn&#8217;t post any comment to the site anymore. So what went wrong?</p>
<p>Normally i use the following lines to do the rewrite.</p>
<blockquote><p>RewriteCond %{HTTP_HOST} ^www\.lenss\.nl$ [NC]<br />
RewriteRule ^(.*)$ http://lenss.nl/$1 [R=301,L]</p></blockquote>
<p>My own site however still runs <a href="http://wordpress.org/">WordPress</a> and this package comes with it&#8217;s own set of rewrite rules. And i just dropped my new lines under the WordPress rewrite rules.</p>
<blockquote><p>RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteCond %{REQUEST_URI} !^.*[^/]$<br />
RewriteCond %{REQUEST_URI} !^.*//.*$<br />
RewriteRule . index.php [L]</p></blockquote>
<p>The result was that the WWW sub domain got rewritten to the no-www version. But everything after the trailing slash got dismissed. So rewrites for blog posts didn&#8217;t work. And all request would land on the main index. So i did some testing and combined the two sets of rewrite rules. This seems to function properly :)</p>
<blockquote><p>RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{HTTP_HOST} ^www\.lenss\.nl$ [NC]<br />
RewriteRule ^(.*)$ http://lenss.nl/$1 [R=301,L]<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteCond %{REQUEST_URI} !^.*[^/]$<br />
RewriteCond %{REQUEST_URI} !^.*//.*$<br />
RewriteRule . index.php [L]</p></blockquote>
<p>Next time i just need to check my changes more thoroughly. And thank you Alex for point that out to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2009/03/wordpress-and-no-www-rewrite/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
