Case Study: Debugging WordPress Plugins (PHP code)
By Angsuman Chakraborty, Gaea News NetworkSunday, June 19, 2005
Today I received a rather angry comment from one of my feed readers and I quote: “Come on! There was absolutely no content in the feed. Not even a teaser. Just ads.” He was justified. To my horror I realized that not only did my feeds failed to provide any content, not even excerpt, but to add insult to injury it dutifully appended the feeds with advertisements. Now that is not good and definitely not my intention, not in thousand years. Here is a brief description of my debugging process.
I began my debugging session by de-activating all the plugins which I suspected to be even remotely associated to feeds. First I deactivated the Ad Engine (though I later realized it was perfectly innocent).
Initially I suspected that strange characters in any post might be causing this problem. So I checked individual category feeds. It appeared at least some feeds were working correctly, at least at the excerpt level. This was a mis-direction which I found out later. At that time most of the plugins were disabled. However the feed content still failed to load.
The first issue was that feeds did not reload on browsers when it ascertained that the content has not changed over last reload. So I resorted to first telnet and then wget.
Even after disabling most plugins the feeds were not working. After some thinking I realized the post content couldn’t be the problem looking at how only the description field was getting blanked out (not even ads as I had disabled the ad engine). Only one plugin was left - Y!Q related search plugin (I developed). On disabling it things were back to normal!
However I was not happy. I opened the code and realized that I had dutifully prevented the plugin from inserting code when it was in a feed. However I did not return the original content. So this filter effectively blanked out the description of the post when in feed. With this changes I reactivated the plugin. Things were fine now.
So now I started activating all the plugins including Evermore plugin which adds a more nicely after first paragraph.
Now I saw only excerpts were being provided in feed. Obviously Evermore was the culprit. By now I realized what could be the problem. So I modified Evermore to prevent it from inserting more when it is in feed. With that in place, finally all my plugins were back in business.
Problem solved. Time taken: about 40 minutes.
Take home lesson:
1. Start any wordpress debugging session by first deactivating the plugins.
2. Try to analyze concceptually what can go wrong instead of manually debugging the code which is anyway hard with php