Many Wordpress plugins require inserting in your theme files calls to functions they define (examples of this include very useful plugins like Akismet Spam Count, del.icio.us integrator and WP Admin Bar). This causes problems when the corresponding plugin is disabled (for example, as suggested for the Wordpress 2.0 upgrade process). Avoiding this problem is extremely easy – instead of simply calling the function, check if it is defined first. For example, instead of inserting
use the following:
That’s it! If the plugin is disabled, the function will simply not be called. I would encourage plugin authors to suggest this syntax instead of the plain calls, as it makes it much easier to experiment with the plugins without having to modify the theme files every time.
1 response so far ↓
1 cavemonkey50 // Mar 13, 2006 at 6:33 am
Great tip! I’ve been using this PHP function for sometime now. It’s very useful if you’re making a theme that is going to be distributed. You can easily include support for plugins without requiring them.