PluginProbe
Autoptimize / 3.0.3
Autoptimize v3.0.3
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
← All changes | classes/autoptimizeBase.php +22 -8 2.7.63.0.3 View file →
@@ -76,8 +76,12 @@
76 76 public function getpath( $url )
77 77 {
78 78 $url = apply_filters( 'autoptimize_filter_cssjs_alter_url', $url );
79 79
80 + if ( is_null( $url ) ) {
81 + return false;
82 + }
83 +
80 84 if ( false !== strpos( $url, '%' ) ) {
81 85 $url = urldecode( $url );
82 86 }
83 87
@@ -94,8 +98,10 @@
94 98 }
95 99 } elseif ( ( false === $double_slash_position ) && ( false === strpos( $url, $site_host ) ) ) {
96 100 if ( AUTOPTIMIZE_WP_SITE_URL === $site_host ) {
97 101 $url = AUTOPTIMIZE_WP_SITE_URL . $url;
102 + } elseif ( 0 === strpos( $url, '/' ) ) {
103 + $url = '//' . $site_host . autoptimizeUtils::path_canonicalize( $url );
98 104 } else {
99 105 $url = AUTOPTIMIZE_WP_SITE_URL . autoptimizeUtils::path_canonicalize( $url );
100 106 }
101 107 }
@@ -143,8 +149,16 @@
143 149 if ( $site_host !== $content_host ) {
144 150 // As we replaced the content-domain with the site-domain, we should match against that.
145 151 $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_SITE_URL );
146 152 }
153 +
154 + if ( is_multisite() && ! is_main_site() && ! empty( $this->cdn_url ) && apply_filters( 'autoptimize_filter_base_getpage_multisite_cdn_juggling', true ) ) {
155 + // multisite child sites with CDN need the network_site_url as tmp_ao_root but only if directory-based multisite.
156 + $_network_site_url = network_site_url();
157 + if ( strpos( AUTOPTIMIZE_WP_SITE_URL, $_network_site_url ) !== false ) {
158 + $tmp_ao_root = preg_replace( '/https?:/', '', $_network_site_url );
159 + }
160 + }
147 161
148 162 $tmp_url = preg_replace( '/https?:/', '', $url );
149 163 $path = str_replace( $tmp_ao_root, '', $tmp_url );
150 164
@@ -155,9 +169,13 @@
155 169 return false;
156 170 }
157 171
158 172 // Prepend with WP_ROOT_DIR to have full path to file.
159 - $path = str_replace( '//', '/', WP_ROOT_DIR . $path );
173 + $path = str_replace( '//', '/', trailingslashit( WP_ROOT_DIR ) . $path );
174 +
175 + // Allow path to be altered, e.g. in the case of bedrock-like setups where
176 + // core, theme & plugins might be in different locations on the filesystem.
177 + $path = apply_filters( 'autoptimize_filter_base_getpath_path', $path, $url );
160 178
161 179 // Final check: does file exist and is it readable?
162 180 if ( file_exists( $path ) && is_file( $path ) && is_readable( $path ) ) {
163 181 return $path;
@@ -300,15 +318,14 @@
300 318 $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $this->cdn_url );
301 319
302 320 // Allows API/filter to further tweak the cdn url...
303 321 $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
304 - if ( ! empty( $cdn_url ) ) {
305 - $this->debug_log( 'before=' . $url );
322 + if ( ! empty( $cdn_url ) && false === strpos( $url, $cdn_url ) ) {
306 323
307 324 // Simple str_replace-based approach fails when $url is protocol-or-host-relative.
308 325 $is_protocol_relative = autoptimizeUtils::is_protocol_relative( $url );
309 326 $is_host_relative = ( ! $is_protocol_relative && ( '/' === $url[0] ) );
310 - $cdn_url = rtrim( $cdn_url, '/' );
327 + $cdn_url = esc_url( rtrim( $cdn_url, '/' ) );
311 328
312 329 if ( $is_host_relative ) {
313 330 // Prepending host-relative urls with the cdn url.
314 331 $url = $cdn_url . $url;
@@ -320,13 +337,10 @@
320 337 $site_url = str_replace( array( 'http:', 'https:' ), '', AUTOPTIMIZE_WP_SITE_URL );
321 338 } else {
322 339 $site_url = AUTOPTIMIZE_WP_SITE_URL;
323 340 }
324 - $this->debug_log( '`' . $site_url . '` -> `' . $cdn_url . '` in `' . $url . '`' );
325 341 $url = str_replace( $site_url, $cdn_url, $url );
326 342 }
327 -
328 - $this->debug_log( 'after=' . $url );
329 343 }
330 344
331 345 // Allow API filter to take further care of CDN replacement.
332 346 $url = apply_filters( 'autoptimize_filter_base_replace_cdn', $url );
@@ -658,9 +672,9 @@
658 672 '.min.' . $type,
659 673 'js/jquery/jquery.js',
660 674 );
661 675 foreach ( $minified_variants as $ending ) {
662 - if ( autoptimizeUtils::str_ends_in( $filepath, $ending ) ) {
676 + if ( autoptimizeUtils::str_ends_in( $filepath, $ending ) && true === apply_filters( 'autoptimize_filter_base_prepare_exclude_minified', true ) ) {
663 677 return false;
664 678 }
665 679 }
666 680