How to Override a Pluggable Function

How can I override a function in pluggable.php?

I have tried making my own plugin — got the fatal error on function already defined.

Read More

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 = '') {
...
}

Related posts

Leave a Reply

2 comments

  1. 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.