Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local image exists check fails for local images' srcset attribute #7

robincornett opened this issue Jun 5, 2019 · 1 comment


None yet
1 participant
Copy link

commented Jun 5, 2019

If an image exists locally and is output with a srcset attribute, it fails the local_image_exists check, so the plugin replaces the URLs in the srcset with the production URL.

It looks like this is because the [image_attr]( method passes the srcset value to the image updater, but the local image check is expecting a URL, and the srcset will be a string such as:

http://local.example.test/wp-content/uploads/2019/05/tim-foster-264461.jpg 4599w, http://local.example.test/wp-content/uploads/2019/05/tim-foster-264461-300x206.jpg 300w, http://local.example.test/wp-content/uploads/2019/05/tim-foster-264461-768x526.jpg 768w, http://local.example.test/wp-content/uploads/2019/05/tim-foster-264461-1024x702.jpg 1024w

which will not return true for the file existing.

Actually, I think all that needs to happen is to change line 159 to this:

$attr['srcset'] = $this->update_image_url( $attr['src'] );

(passing just src to the updater instead of srcset... this fixed the issue for me locally.


This comment has been minimized.

Copy link

commented Jun 6, 2019

Related: local images used in the WordPress core cover block (as a background) end up failing the local_image_exists check as well because the regex done on images in the content doesn't remove the trailing ) from the image path.

One way to fix it would be to just strip any ) from image URLs in the content, inserting this right before line 201:

$url     = str_replace( ')', '', $url );

but there may be a better way to resolve that in the regex itself; my regex wobbles. But adding this line above the $new_url assignment does work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.