WP good practices

please stop checking if a var is != null and use isset() instead!



Custom Data disappears on Custom Post Types

With WordPress 3.0 Custom Post Types came to life and within the project I am working on we started to use them, each post needs to have a set of custom data to associate with. Basically we were adding new posts with custom data and everything was looking fine in the front end, but after a while the custom data would disappear from the blog entry without any post update being performed on the backend… strange strange voodoo. Some checks on the logs and on the database showed no errors so something else was triggering this behavior, there was no voodoo at all this was due to the “autosave” routine performed when you have the “Edit Post” page on the dashboard open.

The problem is that the autosave option does not pass by post the Custom Fields we add to the Custom Post type so when the “save post data” is called those fields are set to blank and you loose your data. Its extremely easy to avoid this by adding an extra hidden field which will work as an id for your custom data form.

echo '<input type="hidden" name="myplugin_noncename" id="myplugin_noncename" value="' .wp_create_nonce( plugin_basename(__FILE__) ) . '" />';

This id will then be used when you save the post data to check if the request came from the “edit post” screen and with proper authorization since this could be triggered at other times.

You can use this code for that purpose:

if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) )) {
return $post_id;

Another possible solution is to simple check if the save post data was triggered by the autosave routine and if so discard that request since it will not include your custom data.

Here is the code for that which should be also added before the save data is performed,

return $post_id;

more details here!

…and that’s more than enough on this subject 🙂

Meeting the “Happiness Engineers”

I have been working with WordPress for a while now and I must say it amazes me all the time, maybe its a bit girly to say this but WordPress is beautifully designed and I can’t honestly say it better than that. Should have said that personally to Matt Mullenweg last friday here but what can I say the guy is a legend and you always feel that anything you say to legends will sound stupid… well maybe next time.

WordPress 3.0

WordPress 3.0 is out with a lot of exciting things to explore. Custom post types is one of them and this post by Justin Tadlock explains it verry well.

PDT & Xdebug for Mac OS

In order to take fully advantage of eclipse while developing php I just finish integrating XDebug with PDT (php development tool for eclipse). I must admit it took me a bit more than I would like to but finally I got it. I will not present here the complete process description, there is no need to reinvent the wheel, but only highligh the missing steps that made me get stuck with it for a little while.

First of all we need to install XDebug, for this you can follow this tutorial.

Give particular attention to step 1, because you need to be sure you are targeting the php instalation for your web browser and not the default one in yout system that you access via the console (they might be different).

Then in step 7 don´t forget the C compiler option CFLAGS='-arch x86_64' otherwise your Apache server will not be able to load XDebuger. This is a missing information on the XDebug install instructions since its system dependent.

After having XDebug installed please reload the phpinfo() page and double check the option set for “xdebug.remote_enable” if this is set to Off you shoudl open the php.ini file and set it to On with the following lines:


Save the file and reload the Web Server.  When you Debug as a Web Page  this option will prevent eclipse to hang waiting for Xdebug session to start.

After finishing XDebug installation please add PDT to your eclipse installation via the “install new software” option or you can download directly Eclipse with PDT incorporated.

In order to configure XDebug support in PDT follow the instructions provided with the XDebugGuide and you will be set to go!

Fly higher

After deciding that I would quit my job I waited a few more weeks before announcing it. No particular reason, I still had time and I was nervous about the reaction of my boss and co-workers, I kept telling myself that was a stupid thought I was just living my life the way I want the way it makes me happy and no one could say or convince me otherwise. If in one hand I was delaying it on the other hand I wanted to say as soon as possible, take that weight off my shoulders, so someday near the end of January I wrote my resignation letter, print it out and went to my boss office. As soon as I ask for closing the door she knew bad news were coming. We talked for a while and I have to say that she supported me right away. She made her point, “this is not good for the company but I knew you would someday try to fly higher and I am proud of you for taking that step”. It was such a good relieve… then you start telling your colleges some of them want to know what the hell will you be doing, others couldn’t care less, but that’s perfectly normal. The most important thing is that I felt I was in the right path and I felt completely free, I was the owner of my decisions and yes its difficult to stand up in front of everyone and say this is my dream and I am doing it, when you have a nice job and a good lifestyle… but its not on my genes to settle.


The begining

I quit my job.

%d bloggers like this: