How to Force http url scheme in welcome email

I'm setting up a multisite at http://wlmsite.com. I want to use Stripe for credit card payments so I need to have SSL for at least the /pro-sites page.

I used a stand SSL certificate and forced only the /pro-sits page to https which did the trick with Stripe.

However I noticed that upon registration WordPress sends the welcome email with the https url scheme as the login url. For example https://testsite.wlmsite.com Of course those links result in an error.

The welcome email steup in WordPress includes a placehoder BLOG_URL which is created by the WP file ms-blogs.php. It uses PHP_URL_SCHEME to aprse out the url of the registration page (which is https) and inserts the https in the login url sues in the Welcome email.

I was able to hack ms-blogs.php to insert only http into the url. But as you know it's a very bad idea to hack WP core.

I know this is not a Pro Sites issue, but I wondered if you guys have a workaround or a filter to fix this. Or should I just bite the bullet and get a wildcard SSL.

Thanks for your advice.

Bob

  • Adam Czajczyk

    Hello Bob,

    I hope you're well today and thank you for your question!

    The registration e-mail - as you already noticed - makes use of BLOG_URL placeholder that is replaced with the value returned by core WP function that's using the URL of the site. In case your main site is set to use HTTPS WordPress will return https:// URL and therefore it will be used in an e-mail.

    That said, the "welcome e-mail" is sent with "wpmu_welcome_notification()" function. It substitutes "BLOG_URL" placeholder with value retrieved by "get_blogaddress_by_id($blog_id);" function. It seems though that we can't hook to that function directly so let's try to modify the welcome e-mail without breaking WP native feature. To do this, we'll hook up to "update_welcome_email" filter like this:

    <?php 
    
    add_filter( 'update_welcome_email', 'wpmu_no_https_welcome_email', 10, 6);
    function wpmu_no_https_welcome_email ($welcome_email, $blog_id, $user_id, $password, $title, $meta) {
            // Override the email body:
            $welcome_email = __( 'Dear User,
    
    Your new SITE_NAME site has been successfully set up at:
    BLOG_URL
    
    You can log in to the administrator account with the following information:
    
    Username: USERNAME
    Password: PASSWORD
    Log in here: BLOG_URLwp-login.php
    
    We hope you enjoy your new site. Thanks!
    
    --The Team  SITE_NAME' );
    
            $current_site = get_current_site();
            $url          = get_blogaddress_by_id($blog_id);
    		// let's replace HTTPS: with HTTP:
    		$url = str_ireplace('https:', 'http:', $url);
            $user         = get_userdata( $user_id );
    
            return str_replace(
                array( 'SITE_NAME', 'BLOG_TITLE', 'BLOG_URL', 'USERNAME', 'PASSWORD' ),
                array( $current_site->site_name, $title, $url, $user->user_login, $password ),
                $welcome_email
            );
    }

    In order to give this code a try, please create an empty file with a .php extension, past that code inside, save file and upload it to your server to /wp-content/mu-plugins/ folder of your Multisite install. If there's no "mu-plugins" folder inside "wp-content" just create it.

    Let me know if it helped please!
    Best regards,
    Adam

  • Milan

    Hello @bob85,

    I hope you are well today. :slight_smile:

    This time we don't have some more options, :slight_frown: we need to go with core edit for this change. Its simple edit so whenever you update plugin you just need to make this change and it will be good to go solution. :slight_smile:

    #1) Open up /wp-content/plugins/pro-sites-files/lib/ProSites/View/Front/Gateway.php file and navigate yourself to line no. 637.
    #2) Replace statement on that line with something like this,

    $blog_admin_url = admin_url(' ', 'http');

    #3) Save changes.

    That's it. :slight_smile: There is one hook for that function which we can use to change site's url but after bit googling some developer folks suggested that its not good to hook your function into https://developer.wordpress.org/reference/hooks/site_url/ filter as some of the scrips which relay on site url may break down.

    However if you have something to play with this hook please do share with us. :slight_smile:

    Please let us know if there is anything else in which we can help you with. :slight_smile:

    Cheers,
    Milan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.