Opened 19 years ago
Closed 19 years ago
#4046 closed defect (bug) (fixed)
script-loader not https compatible
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 2.2 | Priority: | normal |
| Severity: | normal | Version: | 2.1.2 |
| Component: | General | Keywords: | has-patch 2nd-opinion |
| Focuses: | Cc: |
Description
When siteurl starts with https, the function _print_scripts in wp-includes/script-loader.php outputs a wrong url, because it checks for the existence of "http://" at the beginning of the url, and mistakenly prepends a second time the siteurl.
My patch:
Replace this line:
$src = 0 === strpos($this->scripts[$handle]->src, 'http://') ? $this->scripts[$handle]->src : get_option( 'siteurl' ) . $this->scripts[$handle]->src;
with this code:
$src = $this->scripts[$handle]->src;
if (!preg_match("/^https?:\/\//", $src)) {
$src = get_option( 'siteurl' ) . $src;
}
Attachments (3)
Change History (8)
#2
@
19 years ago
This is what I use on my site:
<?php
/*
Plugin Name: SSL Backend
Plugin Author: Jeremy Visser
*/
$swp_is_backend = ( false !== strpos($_SERVER['REQUEST_URI'], '/wp-admin/') );
$swp_should_ssl = ( $swp_is_backend || isset($_SERVER['HTTPS']) );
function swp_siteurl($url) {
// presumes siteurl is set to a http:// address in the options
return str_replace('http', 'https', $url);
}
if ($swp_should_ssl)
add_filter('option_siteurl', 'swp_siteurl');
?>
Yeah, I know. I should be using preg_replace instead, but I can't be bothered to learn regular expressions properly.
#3
@
19 years ago
- Milestone changed from 2.4 to 2.2
- Owner changed from anonymous to rob1n
- Priority changed from low to normal
- Status changed from new to assigned
I think replacing the strpos() with either a preg_replace or two strpos()'s would be good. Working in patch for a regex solution.
Note: See
TracTickets for help on using
tickets.
I had the same problem with my SSL backend, but I found a better solution was to filter "option_siteurl" dynamically, which had the advantage of fixing plugins as well.
I can't pretend my method was without its problems, though. WP-SlimStat got a little inaccurate with the URLS reported.