Musings about technology and other neat stuff

BrT random header image

Avoiding undefined function errors when disabling plugins

March 6th, 2006 · 1 Comment

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, 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.

Technorati Tags: , ,

Tags: ·

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.