I have recently updated from 4.1 to 4.4 directly and I can't override wp_new_user_notification anymore.

Obviously the function should not exist when the plugins are loaded. I wrote a mu-plugin with the following:

add_action('plugins_loaded', function() {
    $reflFunc = new ReflectionFunction('wp_new_user_notification');
    error_log(date('H:i:s', strtotime('now')) . ":\n" . print_r(['action' => current_filter(), 'exists' => function_exists('wp_new_user_notification'), 'defined' => $reflFunc->getFileName() . ':' . $reflFunc->getStartLine()], true) . "\n", 3, trailingslashit(WP_CONTENT_DIR) . 'debug.log');

and the output always is:

    [action] => plugins_loaded
    [exists] => 1
    [defined] => /var/www/wordpress/web/wp-includes/pluggable.php:1742

Any ideas on what might be happening here?

For the sake of completeness. In my plugin file I have:

// this overrides the default welcome email
if (!function_exists('wp_new_user_notification')){ 
    function wp_new_user_notification($user_id, $deprecated, $notify) {
        $welcome = new \PiEmail\WelcomeEmail();
  • Plugins are loaded before pluggable.php, but the plugins_loaded action fires after pluggable.php is loaded. You can see this in the source of wp-settings.php where this happens. – Milo Jan 11 '16 at 19:21
  • I am fully aware of that. The ['exists'] element might be a bit misleading as I know that the function is defined at that point. – alpipego Jan 11 '16 at 19:23
  • If I put if(!function_exists('wp_new_user_notification')){ die('overridden'); } in a plugin in a new 4.4.1 install, I see the overridden message. – Milo Jan 11 '16 at 19:29
  • Thanks for your effort but I don't see that. The function seems to be defined before the plugins' function is registered... – alpipego Jan 11 '16 at 19:31
  • I'd guess you've got some other code in a theme or plugin that appears to be doing something wrong then. – Milo Jan 11 '16 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.