August, 2009

Upgrading widgets to WordPress 2.8 – solving naming conventions

Monday, August 17th, 2009

I’ve just been upgrading a website to WordPress 2.8 that makes great use of widgets, and was having problems with it recognising the custom widgets that I had built and had converted to use the new WP_Widget class.

The code that I had used as my basis had worked fine with a clean install of WP2.8 but didn’t like widgets that had been created under WP2.7.

An hour later of googling & trawling through the source code and I was none the wiser. Then I noticed that WP_Widget automatically adds on ‘widget_’ as a prefix to the id_base property. I had used a different naming convention when I had built custom widgets (e.g. starting them with the project or client name, such as ‘redefine_’…).

If I set the option_name property so that it was just the id_base then all of my widgets successfully reappeared in the upgraded site – but…