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?


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 = '') {
  • Out of curiosity, which function are you trying to override? And can you provide the code (or a snippet) so we can see in what scope you are defining your function?
    – William
    Jun 26, 2012 at 15:07
  • @William -- I revised my question to include the function() I am trying to override.
    – frank13
    Jun 26, 2012 at 15:10
  • Try putting the code in your theme functions.php and setting define('WP_DEBUG', true); in your wp-config.php file so you can see what errors are being thrown. EDIT: by "the code" I mean your function override.
    – William
    Jun 26, 2012 at 15:11
  • Ok, will do @William. I got the white screen first time through...this time I will use debug. My guess is it will yell at me for a duplicate fucntion.
    – frank13
    Jun 26, 2012 at 15:15

2 Answers 2


Wrap it in a function_exists check:

if( ! function_exists('some_pluggable_function') ) {
    function some_pluggable_function()
  • Thanks @Milo but that merely prevents the fatal error. It does not result in my function superseding the pluggable.php call hence my function ends up not running -- the pluggable.php function does.
    – frank13
    Jun 26, 2012 at 14:55
  • 1
    Here's the answer: See sltaylor.co.uk/blog/… It does not make sense that you need to wrap your overriding function with the function_exists() even though it is wrapped in pluggable.php, but you do! That's the trick. SO you are right @Milo.
    – frank13
    Jun 26, 2012 at 15:42
  • 3
    the reason it needs to be wrapped in function_exists is because within the context of a plugin activation, the function does already exist. This is due to the way WordPress activates plugins in a sandbox, which is necessary to enable it to recover from fatal errors in the activated plugin. Technically, once the plugin is activated the function_exists check would not be necessary, but you'd never be able to activate that plugin via conventional means without it.
    – Milo
    Sep 24, 2012 at 15:57

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 in pluggable.php since the WP one is wrapped in a call to function_exists().

But make sure you're only doing this once. From the Codex:

Note: 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.

From what you describe happening, it sounds like more than one plugin is trying to override the same function.

  • 1
    Thanks @EAMann but "I have tried making my own plugin -- got the fatal error on function already defined."
    – frank13
    Jun 26, 2012 at 15:13
  • 1
    I've been trying to figure this out for a while now. Wish I found this answer sooner. Now it makes sense why MY plugin can't override the function that another plugin is overriding. :(
    – Garconis
    Oct 11, 2017 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.