Bug in srcset URL substitution
-
The srcset URL substitution has a bug. The plugin attempts to substitute local_url with remote_url. These URLs include the year and month of the upload so this fails when the current year/month is different from the image’s year/month. I had to patch the plugin with this fix:
diff --git a/wordpress/wp-content/plugins/hacklog-remote-attachment/includes/hacklogra.class.php b/wordpress/wp-content/plugins/hacklog-remote-attachment/includes/hacklogra.class.php index ca29263..073ddb6 100644 --- a/wordpress/wp-content/plugins/hacklog-remote-attachment/includes/hacklogra.class.php +++ b/wordpress/wp-content/plugins/hacklog-remote-attachment/includes/hacklogra.class.php @@ -472,14 +472,14 @@ class hacklogra */ public static function replace_attachurl_srcset($sources, $size_array, $image_src, $image_meta, $attachment_id) { - $local_url = self::$local_url; + $local_url = self::$local_baseurl; // using the same logic as WP global $wp_version; if ( version_compare($wp_version, "4.5", '>=') && is_ssl() && 'https' !== substr( $local_url, 0, 5 ) && parse_url( $local_url, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) { $local_url = set_url_scheme( $local_url, 'https' ); } foreach((array) $sources as $index => $source) { - $sources[$index]['url'] = str_replace($local_url, self::$remote_url, $source['url']); + $sources[$index]['url'] = str_replace($local_url, self::$remote_baseurl, $source['url']); } return $sources; }
Please include this fix in the plugin.
- The topic ‘Bug in srcset URL substitution’ is closed to new replies.