Overriding the default WP Multisite notification e-mail

Is it possible to hook in and override the default notification message for WP MS? I know the message being sent out is in /wp-admin/user-new.php

if ( is_multisite() ) {
    function admin_created_user_email( $text ) {
        /* translators: 1: Site name, 2: site URL, 3: role */
        return sprintf( __( 'Hi,
You've been invited to join '%1$s' at
%2$s as a %3$s.
If you do not want to join this site please ignore
this email. This invitation will expire in a few days.

Please click the following link to activate your user account:
%%s' ), get_bloginfo('name'), site_url(), esc_html( $_REQUEST[ 'role' ] ) );
    }
    add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );

    function admin_created_user_subject( $text ) {
        return "[" . get_bloginfo('name') . "] Your site invite";
    }
}

I believe I can do it if I can find the right hook in so that I can remove_filter() and then add my own in. I had been toying with the following (admin_created_user_email2 is my new function):

Read More
function reset_admin_email(){
    remove_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
    add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email2', 1 );
}

I was reading this page that lists the actions/hooks I can tie into, but I can’t figure out which one to use (if any of them will even work)

Does anyone have experience with this to point me in the right direction?

Thanks

Levi

Related posts

Leave a Reply

6 comments

  1. I was able to override the multi-site notification email by adding these:

    remove_filter('wpmu_signup_user_notification_email','admin_created_user_email');
    add_filter('wpmu_signup_user_notification_email',<function_name_here>);
    add_filter('wpmu_signup_user_notification',<function_name_here>);
    add_filter('wpmu_signup_user_notification_subject',<function_name_here>);
    

    Adding the three filters at bottom i.e. email,notification and subject allows you to override the content and the subject of the email.

  2. @user2647 seems to be on the right path, but I think that this is more correct:

    remove_action( 'wpmu_new_user', 'newuser_notify_siteadmin' );
    add_action( 'wpmu_new_user', 'my_notification' );
    
    function my_notification ($user_id) {
      // Make your custom notification here.
    }
    
  3. remove_filter has no effect because /wp-admin/user-new.php runs

    add_filter('wpmu_signup_user_notification_email', admin_created_user_email);

    every time it loads, after plugins_loaded.

    I got this to work by adding a new filter with a lower priority (higher number), so it runs after admin_created_user_email, which has the default priority (10):

    function reset_admin_email(){
        add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email2', 11 );
    }
    
  4. Would this kind of thing work?

    if ( !function_exists('wp_new_user_notification') ) {
    function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
        $user = new WP_User($user_id);
    
        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);
                $message = $user_login . " " . $user_email;
    
        wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
    
    }
    }
    
  5. Dylan has the correct answer but to elaborate.

    Add a filter that fires after the default one using a higher priority then 10:

    add_filter( 'wpmu_signup_user_notification_email', 'wp_new_user_notification', 11 );
    

    The function for the content:

    function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
    
                $user = new WP_User( $user_id );
    
                $user_login = stripslashes( $user->user_login );
                $user_email = stripslashes( $user->user_email );
    
                $message  = sprintf( __('New user registration on %s:'), get_option('blogname') ) . "rnrn";
                $message .= sprintf( __('Username: %s'), $user_login ) . "rnrn";
                $message .= sprintf( __('E-mail: %s'), $user_email ) . "rn";
    
                @wp_mail(
                    get_option('admin_email'),
                    sprintf(__('[%s] New User Registration'), get_option('blogname') ),
                    $message
                );
    
                if ( empty( $plaintext_pass ) )
                    return;
    
                $message  = __('Hi there,') . "rnrn";
                $message .= sprintf( __("Welcomeeee to %s! Here's how to log in:"), get_option('blogname')) . "rnrn";
                $message .= wp_login_url() . "rn";
                $message .= sprintf( __('Username: %s'), $user_login ) . "rn";
                $message .= sprintf( __('Password: %s'), $plaintext_pass ) . "rnrn";
                $message .= sprintf( __('If you have any problems, please contact me at %s.'), get_option('admin_email') ) . "rnrn";
                $message .= __('Adios!');
    
                wp_mail(
                    $user_email,
                    sprintf( __('[%s] Yourrrrrrr username and password'), get_option('blogname') ),
                    $message
                );
            }
    
    • This code is a copy paste from Codex example.
    • Referenced directly in core here.

    Finally drop it into the mu-plugins folder wp-content/mu-plugins

  6. Most of the text in those emails is translatable, which means we can tap into WP’s gettext filter. I found the following method of implementing translations online but can’t find the original source.

    First define your filter hook:

    add_filter('gettext', [new AddAction(), 'gqa_text_strings'], 20, 3);

    Then your translation function:

     /**
     * Change a few text strings related to the login/registration process
     *
     * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
     *
     * @param $translated_text
     * @param $text
     * @param $domain
     *
     * @return string
     */
    function gqa_text_strings($translated_text, $text, $domain)
    {
        switch ( $translated_text ) {
            case 'Get your own %s account in seconds' :
                $translated_text = __('Request access to %s', 'gqa');
                break;
            case 'We send your registration email to this address. (Double-check your email address before continuing.)' :
                $translated_text = __('', 'gqa');
                break;
            case 'But, before you can start using your new username, <strong>you must activate it</strong>.' :
                $translated_text = __('An email with login instructions has been sent to the address you provided.', 'gqa');
                break;
            case "Check your inbox at %s and click the link given." :
                $translated_text = __('Check your inbox at %s.', 'gqa');
                break;
            case 'If you do not activate your username within two days, you will have to sign up again.' :
                $translated_text = __('', 'gqa');
                break;
            // Subject line for new user registration email
            case 'New %1$s User: %2$s' :
                $translated_text = __('Your account information');
                break;
            // Error message when registering a new account with an already used username.
            case 'That username is currently reserved but may be available in a couple of days.' :
                $translated_text = __('A user with that username already exists. Do you already have an account? Please contact site administrators or try again.');
                break;
            // Error message when registering a new account with an already used email address.
            case 'That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.' :
                $translated_text = __('That email address has already been assigned to an account. Do you already have an account? Please contact site administrators or try again');
                break;
        }
    
        return $translated_text;
    }
    

    You know a string is translatable if it’s enclosed in the __() function. So in your case you would add the following:

    case 'Hi, You've been invited to join '%1$s' at
    %2$s as a %3$s. If you do not want to join this site please ignore
    this email. This invitation will expire in a few days. Please click the following link to activate your user account: %%s' :
        $translated_text = __('Whatever you want the email to say', 'gqa');
        break;