How can I override a function in pluggable.php?
I have tried making my own plugin — got the fatal error on function already defined.
I tried functions.php in my theme — got the white screen.
Is it possible to override a pluggable.php function without touching the source code file itself?
Thanks.
Here is the function I wish to override (located in ../wp-includes/pluggable.php):
if ( !function_exists('wp_new_user_notification') ) :
/**
* Notify the blog admin of a new user, normally via email.
*
* @since 2.0
*
* @param int $user_id User ID
* @param string $plaintext_pass Optional. The user's plaintext password
*/
function wp_new_user_notification($user_id, $plaintext_pass = '') {
...
}
Wrap it in a
function_exists
check:The correct way to override functions in
pluggable.php
is to redefine the same function in a plugin. Your plugin’s function will override the one inpluggable.php
since the WP one is wrapped in a call tofunction_exists()
.But make sure you’re only doing this once. From the Codex:
From what you describe happening, it sounds like more than one plugin is trying to override the same function.