0

I'm trying to customise the activation email in WordPress. I'm using WordPress 3.8 Multisite (subdomain).

I added the following code (from http://daan.kortenba.ch/filter-wpmu_signup_user_notification) to my theme's functions.php

 add_filter( 'wpmu_signup_user_notification', 'dk_wpmu_signup_user_notification', 10, 4 );
/**
 * Problem: WordPress MultiSite sends user signup mails from the main site. This is a problem when using domain mapping functionality as the sender is not the same domain as expected when creating a new user from a blog with another domain.
 * Solution: Change the default user notification mail from using the main network admin_email and site_name to the blog admin_email & blogname
 * 
 * @author Daan Kortenbach
 * @link http://daankortenbach.nl/wordpress/filter-wpmu_signup_user_notification/ 
 */
function dk_wpmu_signup_user_notification($user, $user_email, $key, $meta = '') {
    $blog_id = get_current_blog_id();
    // Send email with activation link.
    $admin_email = get_option( 'admin_email' );
    if ( $admin_email == '' )
        $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
    $from_name = get_option( 'blogname' ) == '' ? 'WordPress' : esc_html( get_option( 'blogname' ) );
    $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    $message = sprintf(
        apply_filters( 'wpmu_signup_user_notification_email',
            __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\n" ),
            $user, $user_email, $key, $meta
        ),
        site_url( "wp-activate.php?key=$key" )
    );
    // TODO: Don't hard code activation link.
    $subject = sprintf(
        apply_filters( 'wpmu_signup_user_notification_subject',
            __( '[%1$s] Activate %2$s' ),
            $user, $user_email, $key, $meta
        ),
        $from_name,
        $user
    );
    wp_mail($user_email, $subject, $message, $message_headers);

    return false;
}

However, this has no effect.

For testing purposes I edited /wp-includes/ms-functions.php and changed line 898 to:

function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array() ) {
   echo "core";
   die;
}

and then my theme's functions.php filter to:

add_filter( 'wpmu_signup_user_notification', 'dk_wpmu_signup_user_notification', 10, 4 );
function dk_wpmu_signup_user_notification($user, $user_email, $key, $meta = '') {
   echo "filter";
   die;
}

Then I registered a new user on the front-end site and it says "core", so for some reason the filter isn't working.

  • 1
    I dont see anything wrong with the first part. I would put that code into a plugin instead of the theme. I do see a problem with your test. You edited wpmu_signup_user_notification() and removed the apply_filter(), that is why your filter is not called. – user42826 Dec 18 '13 at 14:56
  • I followed your advice and added the code as a plugin and it fixed it! Not sure why it doesn't work within functions.php. Maybe it runs too late from there? Do you want to post your comment as an answer then I'll accept :) – Chris Dec 18 '13 at 15:16
1

I dont see anything wrong with the first part. The themes function.php might not be loaded when you create the user. I would put that code into a plugin instead of the theme. A quick way to do that is to create a mu-plugin. For example drop that code into: /wp-content/mu-plugins/mymuplugin.php

I do see a problem with your test. You edited wpmu_signup_user_notification() and removed the apply_filter(), that is why your filter is not called.

| improve this answer | |

Your Answer

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

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