Kai Qing
Kai Qing

Reputation: 18843

Wordpress template_directory functions ignore self signed SSL

EDIT - It looks like the cause of the problem was the wordpress HTTPS plugin. If I disable that it works as expected.

All style and script paths are served using the wordpress methods get_template_directory_uri() or relevant equivalent. The docs are pretty clear in the first line:

Retrieve template directory URI for the current theme. Checks for SSL.

However, using a self signed SSL this still returns the http path, which of course causes all css and js to fail.

We're including like so:

<script src="<?php echo get_template_directory_uri(); ?>/js/lib/bootstrap-custom.js"></script>

Does anyone know if there is a workaround that does not require altering every instance where we call get_template_directory_uri() or is this just because the SSL identity is not verified that the function fails to use https?

We used the self signed SSL hoping we could run a quick transaction test with Authorize.net (which may not like self signed SSL anyhow) so we wouldn't have to buy an actual SSL for a test that may take 2 minutes to verify. So much for shortcuts, huh? Any input is appreciated.

Upvotes: 0

Views: 839

Answers (2)

Otto
Otto

Reputation: 2048

You have to dig down a bit to find this, but what it's doing is checking to see if the current request that's being processed is using SSL.

Basically, the is_ssl() function is as follows:

function is_ssl() {
    if ( isset($_SERVER['HTTPS']) ) {
        if ( 'on' == strtolower($_SERVER['HTTPS']) )
            return true;
        if ( '1' == $_SERVER['HTTPS'] )
            return true;
    } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
        return true;
    }
    return false;
}

So, are you hitting this code with an https request?

Upvotes: 1

diggy
diggy

Reputation: 6838

Check how WooCommerce forces SLL on template_directory_uri and stylesheet_directory_uri:

https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-https.php#L23

Upvotes: 1

Related Questions