You are hereHome / WordPress Plugins / Fail Safe WordPress Plugin Invokation

Fail Safe WordPress Plugin Invokation


By Gerd Riesselmann - Posted on 10 January 2005

A lot of WordPress plugins require to change your site's code a bit. My Randomized Blogroll plugin does it, and so do for example the Recent Posts, the Breadcrumb Navigation, and the Subscribe to Commments plugins, which I run on my site.

Changing your site's code normally is done by adding a function call at the approbiate place, like this:

<php some_plugin_function(); ?>

This works fine if the according plugin is enabled, but as soon as it is disabled, PHP will spit out an error saying "Function some_plugin_function not found" and stop processing. This can be very annoying, if you are disabling plugins temporarely, for example due to debug purposes.

However, PHP offers a quite easy way to deal with this. Just check if the function exists (which is: the plugin is enabled and therefore loaded):

<php if ( function_exists("some_plugin_function") )
{
    some_plugin_function();
}
?>

Now, PHP will invoke the function only if the plugin is enabled.

Topics