Multi-blog plugin caveat

Now that has been running for a few days, I have found a potential issue (and a workaround) when running multiple blogs using the mechanism I outlined when the site first went up.

Changing index.php or other standard files

When a new plugin is installed, it often requires a change to index.php or other standard WordPress files, typically because the plugin replaces an existing function with a newer/better or different one.

The issue: Unless you activate the new plugin on all of the sub-sites, they will break when you make the change. For example, if you install the Dumb Comments plugin, you need to replace the old commenting code with a call to dumb\_comments\_link() in the index file. But the new call is only available if the plugin is activated and results in an ugly script error otherwise.

The solution: Use function-exists to ensure that you call the new function only when the user has activated the plugin, like this:

if ( function_exists('dumb_comments_link') ) {
else {
    comments_popup_link(__('No Comment '), 
    __('Comments (1)'), __('Comments (%)'));

Using this code, blogs that have activated the plugin will use the new code, and blogs that are happy with the standard code will be using that. PHP hackers probably knew this ages ago – I just haven’t found anyone recommending it and I am not a PHP hacker so here it is for the rest of us.

Incidentally, doing this also helps for normal single-blog sites. With the extra code, you don’t break your site if you disable a plugin for a while.

The End: Everybody is happy 🙂

One thought on “Multi-blog plugin caveat

Comments are closed.