Open CodyMcMichael opened 4 years ago
I noticed today that wp media regenerate
does not seem to include functionality for updating post content referencing old versions of an image. It was a little confusing given that the Regenerate Thumbnails plugin documentation recommends this WP CLI command as complete replacement for its functionality:
If you have command line access to your server, I highly recommend using WP-CLI instead of this plugin as it’s faster (no HTTP requests overhead) and can be run inside of a screen for those with many thumbnails.
Perhaps it would be relatively straightforward to bring update_usages_in_posts() into WP CLI for feature parity. Otherwise, it could help future users expecting this step to happen if the WP CLI docs and command usage info explicitly noted that post content will not be updated.
Edited to add: I see on closer reading that the content update functionality in Regenerate Thumbnails has been disabled, so makes more sense that this is not in the CLI command either.
This is the same issue as the one here: https://github.com/wp-cli/media-command/issues/130
the bug seems to occur when invoking the --image_size
option
i can confirm that running the command
media regenerate --only-missing
resolved all issues
Steps to reproduce.
wp media regenerate 18 --image_size=large --only-missing
Now the image-1280x540.jpg is created.Solution 1. Replacing the new image by setting a flag.
We have the old file name. Before the image is regenerated the old size is stored in the _wp_attachment_metadata
meta.
After that it's a basic search-replace for the post_content column for old name. > new name.
Questions.
wp_post_update
so it's a propper revision?Solution 2. Add an option for the output as CSV.
wp media regenerate 18 --image_size=large --format=csv
ID,oldfile,newfile,imagesize
18,2021/10/image-1024x432.jpg,2021/10/image-1280x540.jpg,large
This way every user can loop over this output themselves and the questions for Solution 1 can be implemented freely based on every usecase.
I removed the bug
label from this issue and changed the title to Offer flag to update post content when regenerating thumbnails
We're fixing the missing metadata bug with https://github.com/wp-cli/media-command/issues/130
Describe the current, buggy behavior
I’m using
wp-cli 2.4.0
. I recently built a client a new theme and updated the large image size to fit their new theme. I then ran the commandwp media regenerate --image_size=large --only-missing
to regenerate new large thumbnails. Everything worked as planned. All new images were created, the old were removed, however none of the posts were updated with the new image size. They were all referencing the old images even though they no longer existsDescribe how other contributors can replicate this bug
Update large image size in
settings > media
run commandwp media regenerate --image_size=large --only-missing
Describe what you would expect as the correct outcome
The command would go through all images and regenerate the large image size to the new image size. It should delete the old images and update the posts to which those images were attached with the new image size.
Let us know what environment you are running this on Dev, Staging, Production