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

fix: fix overwriting files with webp filter #2876

Closed

Conversation

bitfactory-robin-martijn
Copy link
Contributor

Related:

Issue

When using the webp filter, the new filename is filename.webp. As a result, filename.jpg and filename.png would both create filename.webp, thus overwriting each other.

Solution

I now include the original file extension in the new file. I've chosen to keep the original format, and simply add .webp behind it. This makes the original structure as clear as possible. Adding a dot is perfectly legitimate on every filesystem.

Impact

After merging this, new files will be created in instances where the webp filter is already used. There's no way around that, however.

Usage Changes

N/A

Considerations

When updating the tests, I noticed that there is a bug in the current way this filter works, for which I created a new issue: #2875

Testing

I updated the existing tests.

@gchtr
Copy link
Member

gchtr commented Jan 29, 2024

We definitely need to discern the file types in the file names. Thanks for taking this on @expedition-robin-martijn!

As with all the PR involving file name changes for images, I wonder how we should handle this properly. Because this will cause a lot of files to be regenerated. It could cause lots of max execution errors and could quickly fill up space on some hosts and leave the uploads folder with lots of unused files.

Could we somehow add a migration path so that developers have a way to fix this on their sites?

  • Provide a way to delete all deprecated (or even all) WebP files using the WP CLI.
  • But then again, not all hosts allow you to run WP CLI. So maybe we could add integrations for popular image regeneration plugins that could handle the migration as well.
  • Maybe save generated WebP files to a different folder, as envisioned in Big ticket about Image handling #2866

I wonder whether we even should put this change behind a filter hook. The filter could be applied for all new Timber installations. For existing installations, we could maybe work with a flag that is saved in the wp_options database and is deleted once the change is through. Depending on the flag, we could show a notification in the admin dashboard.

I’m just thinking out loud here and am happy about better ideas.

@Levdbas
Copy link
Member

Levdbas commented Feb 27, 2024

I have a feeling that we have to take the deep dive her as suggested by @nlemoine in #2866 and separate generated files at some point from the original media library. The tasks involved here would be so substantial we could dedicate a whole release to it. Now we just have to find the time to actually make such a big improvement.

So in hindsight, I think this PR can give us some ideas for handling filenames in that future release, but I think we cannot merge this as is. But thank you so much @expedition-robin-martijn , for taking the time to help with shaping the full solution.

@bitfactory-robin-martijn
Copy link
Contributor Author

This completely makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants