Codex tools: Log in / create account
Pluggable functions in WordPress 1.5.1+ let you replace certain core functions with functions of your own using a plugin. A function can only be reassigned this way once, so you can’t install two plugins that plug the same function for different reasons. For safety, it is best to always wrap your functions with if(!function_exists()), otherwise you will produce fatal errors on plugin activation.
The default functions are defined in wp-includes/pluggable.php.
An example of what you can do with a pluggable function is replace the default email handler. To do this, you'd need to write a plugin that defines a wp_mail() function. The default wp_mail() function looks like this:
function wp_mail($to, $subject, $message, $headers = '') {
if( $headers == '' ) {
$headers = "MIME-Version: 1.0\n" .
"From: " . get_settings('admin_email') . "\n" .
"Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
}
return @mail($to, $subject, $message, $headers);
}
But, for example, if you wanted to CC all your mail to another address, you could use this code in a plugin:
if(!function_exists('wp_mail')) :
function wp_mail($to, $subject, $message, $headers = '') {
if( $headers == '' ) {
$headers = "MIME-Version: 1.0\n" .
"From: " . get_settings('admin_email') . "\n" .
"Cc: dummy@example.com\n";
"Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
}
return @mail($to, $subject, $message, $headers);
}
endif;
Notice that if you plug a core function like this the original is no longer available. I.e., the elegant solution here would have been to write a function that tacks our Cc header on the end of the exising $headers string then call the original wp_mail() with the extra header. However this would not work as the original wp_mail() does not exist if you plug it.