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



Stop Forum Spam
Do you ever wonder why your blog is receiving comments in Russian cyrillic? Get the visitor maps plugin, and bookmark the stopforumspam.com site. You can enter the commentor’s email address, the home website they claim, even their IP address – which you can see in the visitor maps plugin. Every single one of these russian commentors shows up on the stopforumspam website, without exception.
These people, mostly from Prieli Latvia in my case, are trying to increase their SEO visibility by adding comments to our blogs. Don’t let them. I have my akismet spam filter set to mark all comments coming from the .ru domain as spam.
Akismet -
You can register with Akismet (wordpress.com actually) without having to sign up for a blog. They will email to you an API key (a short string of numbers and letters), you configure your Akismet plugin with this. It costs nothing, I have never received any email from Akismet nor have been bothered by them in any way.
[Translate]