Hacking WordPress…

November 19, 2004 | Blogging, Web Programming | By: Mark VandeWettering

I’ve been thinking for sometime that I should really try out the new development version of WordPress. I hacked some crude support for enclosures into my version, but I heard that there was some new code that is supposed to deal with it in the current version, so I thought I’d give it a try.

The way that I hacked the system was by the use of custom fields: basically I added two fields audiourl and audiolength, which if they were present in a posting would:

  • add the necessary enclosure tag to the RSS feed, and
  • add a link with the word “Enclosure” and the size to the posting so those without ipodder scripts could download the mp3 file

This worked fine, but was sub-optimal because it required me to type in the size of the audio enclosure itself. In the CVS version of WordPress, any link to an audio, video or image file is included in the feed as an enclosure, and the code in WordPress is smart enough to try to fetch the header for the requested item to get its Content-type and its Content-length, so that simplifies the overall process.

It took me only a few minutes to go back through my database using a python script and the MySQLdb package and issue the appropriate UPDATE SQL commands to switch one to the other. Et voila! It worked just fine.

While I was trying out the new version, I noticed that it loaded the index page much faster than mine. The key difference would seem to be the right column, and in particular the code that I got from Chaitgear for tracking referers. Digging in the code, found that it does a wasteful SELECT that probably fetches the entire list of referers. Putting a limit onto that query results in the same result, but operates much faster. That’s in place now.

If the CVS version of WordPress checks out, I’ll probably try to deploy it as soon as I can port my brainwagon “theme” over to it.