When you upgrade, you should deactivate your plugins because it may help to prevent errors. The problem is that if you deactivate plugins that itself can cause errors. So this will sort that for you.


Plugin code

Many plugins ask you to put code into your theme so the plugin works. Things like:
<?php get_recent_comments(); ?>
<?php get_recent_posts(); ?>
<?php kramer_inbound(); ?>
There is nothing wrong with them, but if the plugin stops for some reason or if you deactivate it, then you will get an error instantly. Not good.

So the trick is to wrap them up.


If it's not there, ignore it

Before WP does what the plugin says, it should check that the plugin is there by checking that the function is there. By the time WP gets along to putting your page on the screen for a visitor, it already knows what functions it can use, so the code you will put in simply asks WP to check if the function is in it's list and if it is, to do something. No function and the plugin function will be ignored.


Here is an example from one of those above:

<?php get_recent_comments(); ?>
would turn into
<?php if (function_exists('get_recent_comments')) get_recent_comments(); ?>

The code is saying IF the function exists, use it otherwise forget about it.

Another example... a function that displays the latest posts
<?php get_recent_posts(); ?>
turns into
<?php if (function_exists('get_recent_posts')) get_recent_posts(); ?>

A more complex example. Let's say you have a plugin that you need to use arguments / parameters with. All you need to check is the function, not any of the extra stuff. For instance, you have this in your sidebar and it works just fine:
<?php get_a_feed('http://www.carrot.com','5','li','/li','true'); ?>
would turn into
<?php if (function_exists('get_a_feed')) get_a_feed('http://www.carrot.com','5','li','/li','true'); ?>

If you can take a few minutes to wrap any plugin code like that, it will save you trouble at a later date. And if you are not sure just quite how to get something right, ask in the forums :)

 

These pages are independent of http://wordpress.org
All design, content & images © Mark 2004-2008. All rights reserved.