Repository navigation
Offer flag to update post content when regenerating thumbnails #121
Description
Activity
I noticed today that
wp media regeneratedoes 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:
#130the bug seems to occur when invoking the
--image_sizeoptioni can confirm that running the command
media regenerate --only-missing
resolved all issues- addedcommand:media-regenerateRelated to 'media regenerate' commandRelated to 'media regenerate' command
on Aug 5, 2021 Steps to reproduce.
- Upload a (big image). Let's say it get ID 18
- Edit a post/page. Insert the image in large format.
- Go to media settings. 'large is 1024x432' by default.
Change it to 1280x540 for example. - Run
wp media regenerate 18 --image_size=large --only-missing
Now the image-1280x540.jpg is created. - In the post the 1024x432 image is still included.
The image of 1024x432 does still exists, which is expected.
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_metadatameta.
After that it's a basic search-replace for the post_content column for old name. > new name.Questions.
- Should this be a search-replace on the post or a seperate
wp_post_updateso it's a propper revision? - Which post types are to be affected? All? Only the publicly available?
- The same question for post status. Published or also Drafts? What about trash?
- This might get real slow if there are many posts and images and all images & sizes are regenerated.
- If the old size is replaced everywhere should the old size be removed?
This might cause problems if images are linked outside the current WordPress like in a newsletter or on a multisite.
I guess this could be an other flag-option. - I have no idea if this might break some page builder.
Solution 2.
Add an option for the output as CSV.wp media regenerate 18 --image_size=large --format=csvID,oldfile,newfile,imagesize 18,2021/10/image-1024x432.jpg,2021/10/image-1280x540.jpg,largeThis way every user can loop over this output themselves and the questions for Solution 1 can be implemented freely based on every usecase.
- changed the title
[-]Regenerating thumbnails not updating posts[/-][+]Offer flag to update post content when regenerating thumbnails[/+]on Dec 16, 2022 I removed the
buglabel from this issue and changed the title toOffer flag to update post content when regenerating thumbnailsWe're fixing the missing metadata bug with #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-missingto 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 > mediarun command
wp media regenerate --image_size=large --only-missingDescribe 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