I’m learning how to write wordpress plugins, I’ve said that before here in my blog. One of the ways I’m doing it is by downloading/installing existing plugins I see out there which may be interesting to me – they provide actions and capabilities to do things I want my plugin(s) to do … on a more general scale.
One thing I have noticed – almost all of these plugin authors do NOT use classes in their design. Their .php files are full of functions, most of the time written without the
function my_function() {
// and so on
}
}
or
function my_function() {
// and so on
}
}
endif;
How do they expect to avoid naming collisions? If they have to have a function by a certain name which probably exist in some other plugin developer’s file somewhere, then even if they use this !function_exists business they’ll end up getting the other author’s behavior for that function.
Why don’t these people just use classes! I know I’m coming at this from the java world where you have to use classes for everything, and there’s packaging to avoid naming collisions, but still – this seems like an obvious question to me. Do the modern php programmers have no experience with a real class-oriented language?
Here’s a silly example I’m doing. I have a plugin I’m developing to allow Zlatina’s web administrators to deal with their database of students and contacts. It’s called Bcc DBManager.
I created a subdirectory wp-content/plugins/bcc-dbmanager, with a file named bcc-dbmanager.php … duh. I want to hook into the activate_${plugin} (see this link for an explanation of that). Here’s a partial …
/*
Plugin Name: Bcc DBManager
Description: Blah blah
*/
$bccDBManager = new BCC_DBmanager();
add_action('activate_bcc-dbmanager/bcc-dbmanager.php',
array(&$bccDBManager,'_activate'));
class BCC_DBmanager {
function _activate() {
// do stuff
$this->very_common_function_name();
// or this way
BCC_DBmanager::very_common_function_name();
}
## function with a very common name
function very_common_function_name() {
// do stuff
}
}
?>
How hard is that? I certainly don’t know much about plugin development at this point. But I would have to describe the use of functions rather than class instances and methods as Code Smell.
[Edit] Since I wrote this post I found this link on Nerdaphernalia: Use Classes in your WordPress plugins to increase code portability and reduce name conflicts

Comment translation
I’ve been getting an amazing number of comments on some of my blog entries coming from Russia – and they’re in the Russian language in Cyrillic. I expect there’s some kind of rss-feed going on, I do have several subscribers to this blog who’s personal data indicates their home page is in .ru domain or their email address comes from a .ru domain.
Using the Vistor Maps and Who is Online plugin I’m able to see where my visitors are coming from, at least the country where their IP address is located. Most of the .ru commentors are actually coming from Latvia … from Preili Latvia in particular.
Maybe they’ve put my site on some social networking location in Russia? How is it they’re able to write comments to my blog without appearing in my google analytics report? Why aren’t they writing comments in english, my language? Are my blog entries being translated to Russian where these people are reading them, and if so how good a translation is it?
Since so many of the comments coming from Russia are spam I’ve had to place the .ru domain in my Aksimet filter, but just as many seem to be honest comments coming from regular people. So I go through the comments flagged as spam this way, and on occasion will approve them for the post. I go to translate.google.com to see what they are saying, and to have a look at the website they claim as home page.
Often some innocuous comment such as “good post” comes with a link to some porno or warez site, so I just delete those.
But a they are in Russian, I have to translate all of them this way. So I’m going to try something new. I’ve done a google search for “wordpress google translate plugin“, and have arrived at the following two plugins (links open in new window):
It looks like the Global Translator is more fully developed, and able to use 4 different translator engines (at least claimed on the plugin site), so this is the one I’m going to try.
There is a pro version available, but let’s see how well this plugin works on a site such as mine, with these Russian-language and cyrillic charset comments.
….
Ok, I’ve installed the global translator and I have to admit, it doesn’t do what I want in this case. I only want to be able to translate the comments, not the entire website. The Global Translator has lots of nice options, and it might be useful for my readers who come from those various countries to get a translation of my website in their language, but hey – than can do what I’ve been doing, go to translate.google.com and enter the URL and see the translation.
So I’m going to deactivate that plugin for now, and try the Google Ajax Translator.
….
Very nice. This does what I want. I’m not offering translation of entire pages or posts, I only want to see for myself what these Russian comments are saying. So we’ll see how it works.
And if any of you commenting on my blog entries would like to tell me – where are you seeing my blog? Are my entries translated into your language, is this why you’re writing comments in Russian? I’d like to read your comments about these questions.
[Translate]