DOMAIN MAPPING BREAKS DIVI VISUAL EDITOR

This one appears to be the same issue as in this other closed question:
https://premium.wpmudev.org/forums/topic/domain-mapping-breaks-divi-visual-editor#post-1208826

I was asked to start a new ticket instead of appending to the old one, so here goes :slight_smile:.

I'm using
Divi 3.0.31
Domain Mapping 4.4.2.4
WP 4.7.2

1. I have a multi-site setup.
2. I have a wildcard certificate for *.mydomain.com.
3. Each subdomain-based site may have another domain name mapped. For example, customerdomain.com maps to customerdomain.mydomain.com.
4. I have things set to force HTTPS for back-end admin pages. Therefore, I have things set up to not use domain mapping when on the back-end admin pages (so the user would be looking at pages on https://customerdomain.mydomain.com, which is covered by my wildcard cert.
5. When The new Divi Visual Editor button is presented, it links to https://customerdomain.com/?et_fb=1. Clicking that brings them to a browser warning page that says the domain in the certificate (*.mydomain.com) doesn't match the domain in the URL (https://customerdomain.com).

I don't want to switch off https for the back-end admin pages.
I need to use the Divi theme.

In troubleshooting this, I found their et_fb_prepare_ssl_link looks like this:

function et_fb_prepare_ssl_link( $link ) {
        // replace http:// with https:// if FORCE_SSL_ADMIN option enabled
       if ( defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ) {
           return str_replace( 'http://', 'https://', $link );
       }
       return $link;
}

If I change it to this, then it almost fixes it:

function et_fb_prepare_ssl_link( $link ) {
           // replace http:// with https:// if FORCE_SSL_ADMIN option enabled
           if ( defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ) {
                    $link = str_replace( 'http://', 'https://', $link );
           }
          //This next part checks if it's https and not *.mydomain.com.  If it is, then
         //switch it to the value in  the siteurl option, which is always
         // of the form https://customerdomain.mydomain.com
          if (preg_match("/https\:\/\/(?!.*mydomain\.com)/", $link)) {
                   $link = get_option('siteurl');
          }
         return $link;
}

When I do that, at least it always creates the link to use https://customerdomain.mydomain.com/?et_fb=1 instead of https://customerdomain.com.

However, even with that code patch, for some reason even though hovering over the "Use Visual Builder" the link in the status bar shows https://customer.mydomain.com/?et_fb=1 (desired), after clicking on "Use Visual Builder" somehow it switches back to http://customerdomain.com/?et_fb=1 (which is what I don't want...note now it's not even https anymore).

I suspect this might have something to do with domain mapping switching it back. I hope this extra level of detail helps.

Your advice is much appreciated.

Best,
Dave