diff --git a/inc/app_replacer.php b/inc/app_replacer.php index ceb8cef6..2add874d 100644 --- a/inc/app_replacer.php +++ b/inc/app_replacer.php @@ -205,13 +205,13 @@ public function set_properties() { if ( defined( 'OPTML_SITE_MIRROR' ) && constant( 'OPTML_SITE_MIRROR' ) ) { $this->site_mappings = array( - rtrim( get_site_url(), '/' ) => rtrim( ltrim( constant( 'OPTML_SITE_MIRROR' ), 'www.' ), '/' ), + rtrim( get_site_url(), '/' ) => rtrim( constant( 'OPTML_SITE_MIRROR' ), '/' ), ); } $this->possible_sources = $this->extract_domain_from_urls( array_merge( - array( ltrim( get_site_url(), 'www.' ) ), + array( get_site_url() ), array_values( $this->site_mappings ) ) ); @@ -240,14 +240,23 @@ protected function extract_domain_from_urls( $urls = array() ) { function ( $value ) { $parts = parse_url( $value ); - return isset( $parts['host'] ) ? ltrim( $parts['host'], 'www.' ) : ''; + return isset( $parts['host'] ) ? $parts['host'] : ''; }, $urls ); $urls = array_filter( $urls ); $urls = array_unique( $urls ); - return array_fill_keys( $urls, true ); + $urls = array_fill_keys( $urls, true ); + // build www versions of urls, just in case we need them for validation. + + foreach ( $urls as $domain => $status ) { + if ( ! ( substr( $domain, 0, 4 ) === 'www.' ) ) { + $urls[ 'www.' . $domain ] = true; + } + } + + return $urls; } /** @@ -262,7 +271,8 @@ public function can_replace_url( $url ) { return false; // @codeCoverageIgnore } $url = parse_url( $url ); - return isset( $this->possible_sources[ ltrim( $url['host'], 'www.' ) ] ); + + return isset( $this->possible_sources[ $url['host'] ] ); } /** diff --git a/inc/lazyload_replacer.php b/inc/lazyload_replacer.php index 3088d80f..532465c9 100644 --- a/inc/lazyload_replacer.php +++ b/inc/lazyload_replacer.php @@ -91,12 +91,12 @@ public function lazyload_tag_replace( $new_tag, $original_url, $new_url, $optml_ [ $original_url, 'src=', - 'srcset=', //Not ideal to disable srcset, we should aim to remove the srcset completely from code. + 'srcset=', // Not ideal to disable srcset, we should aim to remove the srcset completely from code. ], [ $low_url, $opt_src . ' src=', - 'old-srcset=' + 'old-srcset=', ], $new_tag ); diff --git a/themeisle-hash.json b/themeisle-hash.json index ab52cf41..0106c87e 100644 --- a/themeisle-hash.json +++ b/themeisle-hash.json @@ -1 +1 @@ -{"optimole-wp.php":"c27858bd3806572aacc60dc98bb8735e"} \ No newline at end of file +{"optimole-wp.php":"ac1b296e575224597f0cba676855333b"} \ No newline at end of file