Ben is a lifelong Nintendo fan who likes to build websites, and make video games. He buys way too much Lego.
Ever heard the saying, ‘the more I learn the less I know’? I often feel that way with WordPress! I like to think that my knowledge of WordPress is above average, but I keep learning new things, and they keep on changing it. My most recent ‘discovery’ is pluggable.php.
Pluggable.php is a php file full of a variety of WordPress functions. I was aware of its existence but until recently I didn’t understand it’s significance. The key thing that makes pluggable.php useful is that all the functions are wrapped in ‘if function_exists‘ calls. This means that you can plug-in (hence the name I guess) your own versions to override the default WordPress functionality.
The reason I found out about this is because I was searching for a way to stop myself from receiving emails when a new user signed up for WordPress Vote. When you have a public site you don’t always want to receive these notifications and so I headed over to Twitter and got the following message from mfields.
The function in question is wp_new_user_notification. In order to stop the emails all I have to do is create a new function with the same name inside my functions.php. If I do this then, because the function already exists, the built-in functionality doesn’t get executed. It couldn’t be easier.
Reading through pluggable.php there are a few different functions in there that it may be useful to override at some time and I have included the ones I find most interesting below. You can read the full list of functions on the pluggable.php code browser on WordPress trac.
- wp_new_user_notification and wp_password_change_notification – these are the reason I first looked into pluggable.php. You can add blank functions to remove the notifications or you could change the email message or email destination to make them more useful.
- wp_generate_password – create your own password generation algorithm
- get_avatar – change the avatar system to use services other than Gravatar (are there any others?)
Pluggable.php isn’t the solution to everything however, as with many things, this is another string to add to your bow. It’s certainly not going to solve all of your WordPress problems, but if there’s something you are not sure about then it could be worth checking out.
Had you looked at pluggable.php before? I’d be interested to know what you are overriding and why.