Do I have to override the wp_mail() pluggable function with writing a plugin?

If I want to override wp_password_change_notification, do I have to write a plugin to do this? It seems to have no effect in functions.php of my theme.

The only thing I need to do is change the wording to lower case.

    if ( !function_exists('wp_password_change_notification') ) :
    /**
     * Notify the blog admin of a user changing password, normally via email.
     *
     * @since 2.7
     *
     * @param object $user User Object
     */
    function wp_password_change_notification(&$user) {
        // send a copy of password change notification to the admin
        // but check to see if it's the admin whose password we're changing, and skip this
        if ( $user->user_email != get_option('admin_email') ) {
            $message = sprintf(__('Password lost and changed for user: %s'), $user->user_login) . "rn";
            // The blogname option is escaped with esc_html on the way into the database in sanitize_option
            // we want to reverse this for the plain text arena of emails.
            $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
            wp_mail(get_option('admin_email'), sprintf(__('[%s] Password Lost/Changed'), $blogname), $message);
        }
    }

endif;

Related posts

Leave a Reply

1 comment

  1. Yes you need to use a plugin. Point is that pluggables are between hard and impossible to control. You can read through this thread on wp-hackers about the actual problems and why you shouldn’t use them.

    Important:

    Note: pluggable.php loads before the ‘plugins_loaded’ hook.

    This means that you need the “MU-plugins” (Must use) hook: mu_plugins_loaded and their folder.

    My recommendation:

    Don’t do it. Not worth the effort and problems coming with it just to get the text of an email lowercase. It’s much easier to directly hook into the wp_mail() filters and actions:

    // Compact the input, apply the filters, and extract them back out
    extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
    
    // Plugin authors can override the potentially troublesome default
    $phpmailer->From     = apply_filters( 'wp_mail_from'     , $from_email );
    $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name  );
    
    $content_type = apply_filters( 'wp_mail_content_type', $content_type );
    
    // Set the content-type and charset
    $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
    
    do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );