Deleting the original file after conversion may cause bugs
-
plus-webp has a feature that automatically converts images to webp format after users upload them.
WordPress has a function that can use ctrl+v to automatically upload the picture in the clipboard when editing an article, and add the picture URL in the article. Normally, the file name of the uploaded image is image. If there is already an image named image, the image name is image-1, image-2, and so on.
If these two functions work independently, they can do a good job. But when using both functions at the same time, the bug appears.
First I uploaded an image using ctrl+v, it was named image.jpg in the media library, plus-webp converted it to webp format, named it image.webp, and automatically deleted image.jpg, which was fine.
Then when I upload a second file using ctrl+v, WordPress still names it image.jpg since image.jpg has been deleted, and that’s the problem.
Now both image.jpg and image.webp exist, so plus-webp can’t do the conversion work because the file name image.webp is already taken.
But it seems that the function of automatic URL replacement is still in effect, so in the editor, the two pictures will be displayed as the first picture.When I uploaded the third image, because image.jpg already existed, WordPress named it image-1.jpg, and now plus-webp can convert it to image-1.webp normally, so the first The three pictures can be displayed normally in the article.
In short, this bug causes users to use ctrl+v to upload pictures, and every second picture will have a bug because it cannot be converted.
I suggest that plus-webp check if the target file name exists before converting the file, for example, before converting image.jpg, check if image.webp already exists, and if it exists, try to convert it to image-1.webp, If image-1.webp also exists, it tries to convert it to image-2.webp, and so on. This approach should solve the above problems.
Since I don’t know PHP programming language, this is just my suggestion, please forgive me if I offend you.
Finally, thank you for the plugin, it’s really nice.
- The topic ‘Deleting the original file after conversion may cause bugs’ is closed to new replies.