SITE_NAME returns networked name instead of new site's name

Hello,
I've a little problem with my network's auto e-mail function.
When a new site is created the SITE_NAME in the welcome e-mail returns my network's name instead of new site's name.
I've tried to deactivate all plugins as JACK told me, but that did not work.
Thanks for your helps in advance.

  • Ash

    Hello @ADET

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    Would you please try the following code?

    function wpmu_welcome_user_notification($user_id, $password, $meta = '') {
        global $current_site;
    
        $welcome_email = get_site_option( 'welcome_user_email' );
    
        $user = new WP_User($user_id);
    
        $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta);
    
        // Get the current blog name
        $blogname = get_option( 'blogname' );
        $welcome_email = str_replace( 'SITE_NAME', $blogname, $welcome_email );
    
        $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
        $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
        $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );
    
        $admin_email = get_site_option( 'admin_email' );
    
        if ( $admin_email == '' )
             $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
    
        $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
        $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
        $message = $welcome_email;
    
        $subject = apply_filters( 'update_welcome_user_subject', sprintf(__('New %1$s User: %2$s'), $blogname, $user->user_login) );
        wp_mail($user->user_email, $subject, $message, $message_headers);
    
        return false; // make sure wpmu_welcome_user_notification() doesn't keep running
    }
    add_filter( 'wpmu_welcome_user_notification', 'bbg_wpmu_welcome_user_notification', 10, 3 );

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • Ash

    Sorry, my bad. Try this please:

    function bbg_wpmu_welcome_user_notification($user_id, $password, $meta = '') {
        global $current_site;
    
        $welcome_email = get_site_option( 'welcome_user_email' );
    
        $user = new WP_User($user_id);
    
        $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta);
    
        // Get the current blog name
        $blogname = get_option( 'blogname' );
        $welcome_email = str_replace( 'SITE_NAME', $blogname, $welcome_email );
    
        $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
        $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
        $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );
    
        $admin_email = get_site_option( 'admin_email' );
    
        if ( $admin_email == '' )
             $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
    
        $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
        $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
        $message = $welcome_email;
    
        $subject = apply_filters( 'update_welcome_user_subject', sprintf(__('New %1$s User: %2$s'), $blogname, $user->user_login) );
        wp_mail($user->user_email, $subject, $message, $message_headers);
    
        return false; // make sure wpmu_welcome_user_notification() doesn't keep running
    }
    add_filter( 'wpmu_welcome_user_notification', 'bbg_wpmu_welcome_user_notification', 10, 3 );

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.