Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to customize the email content and subject for the welcome and verification emails sent during the registration process for Wordpress? I'd like to hook or filter in without using a plugin or the "pluggable" feature.

If someone could point me in the right direction, I'd be very appreciative. Thanks!

share|improve this question
    
Anything you paste in your functions.php is a potential plugin. Also, why can't it be with the pluggable function? Are you sure your Question is not a duplicate? (check the RELATED column at the right) –  brasofilo Feb 5 '13 at 23:37
    
As long as I can perform the action from my functions.php file, I'm down. The issue with plugins is we have many sites on our network and they all work as a collective application vs individual sites. So they all need the same code. Managing the activation of a plugin on each one when created seems like an extreem amount of effort ongoing. –  Jake Lisby Feb 6 '13 at 15:27
    
That is what Must Use plugins are for. –  brasofilo Feb 6 '13 at 15:34
    
So I tried going this route and for some reason it doesn't overwrite the content box available in the Network Settings menu. So although it might auto-activate, it doesn't actually replace anything. I'm using a Multisite Install, so I'm not sure how that effects these pluggable functions. –  Jake Lisby Feb 6 '13 at 17:01

3 Answers 3

I'm afraid you'll have to use the pluggable functions feature - there's no filter or hook inside those functions (as you can see from the code below). And what's worse, for you, it's better to use pluggable function in a plugin.

This is because defining new pluggable function in your theme's functions.php requests you to use a definition of a new function in a function (in order to call it as soon as all plugins are fully loaded), which may be bad (see comments below this post), but on the other hand, it works - see code below the first one.

For those who are not against plugins, here's one which rewrites a pluggable function - just save it into my_plugin.php (or anything else) to you plugins directory and activate from your admin:

<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
if( !function_exists('new_user_notification') ){
function new_user_notifiaction(){
        /**
         * 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 = '') {
            $user = get_userdata( $user_id );

            $user_login = stripslashes($user->user_login);
            $user_email = stripslashes($user->user_email);

            // 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);

            $message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
            $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
            $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";

            @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);

            if ( empty($plaintext_pass) )
                return;

            $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
            $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
            $message .= wp_login_url() . "\r\n";

            wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);

        }
    }
}

Just if you're curious, here a the same efect managed from functions.php with a new function defined inside another function:

//redefine wp_new_user_notification as soon as all plugins are loaded
add_action( 'plugins_loaded', 'new_user_notifiaction' );

function new_user_notifiaction(){
    /**
     * 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 = '') {
        $user = get_userdata( $user_id );

        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);

        // 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);

        $message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
        $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
        $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";

        @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);

        if ( empty($plaintext_pass) )
            return;

        $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
        $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
        $message .= wp_login_url() . "\r\n";

        wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);

    }
}
share|improve this answer
    
Can you provide a third party example of a pluggable function being defined as a function inside a function? It's the first time I'm seeing this... –  brasofilo Feb 6 '13 at 0:11
    
I'm afraid I can't, but it's working ;) Is there somethin' why this approach would cause some troubles? Performance? Integrity? –  david.binda Feb 6 '13 at 0:37
    
I wanted to make sure there was not a copy/paste source for this. It's bad practice to declare a function inside a function. And to override a pluggable you only need if( !function_exists('plug_func') ) { function plug_func() {} }. –  brasofilo Feb 6 '13 at 0:43
    
Yes, that's true that I only need the code you've provided, but in that case my code have to be loaded before the original one. And theme'a functions.php are loaded after the original source in pluggable.php - thus plugins_loaded hook. And any reason for declaring function inside a function being a bad idea? –  david.binda Feb 6 '13 at 0:51
1  
up vote 0 down vote accepted

So I think the answer is no, you aren't able to do this in a safe manner.

share|improve this answer

This seems like a nice idea, which would also work in functions.php:

// Add filter for registration email body
add_filter('wp_mail','handle_wp_mail');

function handle_wp_mail($atts) {
    /*"Your username and password" is the subject of the Email WordPress send from "function wp_new_user_notification" in file "wp-includes/pluggable.php"*/

    if (isset ($atts ['subject']) && substr_count($atts ['subject'],'Your username and password')>0 ) {
    if (isset($atts['message'])) {
       $atts['message'] = 'new body';
    }
    }
    return ($atts);
}

Just watch out for the language to get the right subject string. (Source: http://wordpress.org/support/topic/how-to-change-registration-email-content?replies=3)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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