Avoiding undefined function errors when disabling plugins

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.

Technorati Tags: , ,

Advertisements

One response to “Avoiding undefined function errors when disabling plugins

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s