joppuyo / acf-image-aspect-ratio-crop

Image Aspect Ratio Crop field for Advanced Custom Fields
https://wordpress.org/plugins/acf-image-aspect-ratio-crop/
GNU General Public License v2.0
106 stars 16 forks source link

Invalid URL created when used with other plugin for image resizing. #137

Open NigelRel3 opened 7 months ago

NigelRel3 commented 7 months ago

We use Tachyon for image scaling and this will sometimes add parameters to the image, something like image.webp?resize=10x10.

In the admin site, we found the image was sometimes not displayed after upgrading to a newer node version of the plugin. After some debugging it was found that the url being created in the render_field() method in this plugin was just adding ?v=_hash_ to the end of the url giving a url of image.webp?resize=10x10?v=_hash_. If you take the url and paste it into a browser it fails to load, change the second ? to an & and the image loads. This is down to the second ? being treated as part of the previous parameter rather than as a separate one (according to https://stackoverflow.com/questions/2924160/is-it-valid-to-have-more-than-one-question-mark-in-a-url)

I would think that a simple fix would be to change to code to check for a ? before just appending the v parameter and this should solve the problem and also ensure it's added correctly. Something along the lines of

            // url exists
            if ($url) {
                $url = $url[0] . (strpos($url[0], '?') === false ? '?v=' : '&v=') . md5(get_the_date($image_id));
            }

If I create a PR and add this, is this likely to be added soonish, or should I create a temporary work around to keep the sites working properly.

Thanks Nigel