WordPress-Importer
WordPress-Importer copied to clipboard
Import of pre-WP4.1 images breaks URLs due to change of image scaling/rounding
#30660 changed the scaling behaviour for attachments. Due to that when importing a WXR exported from pre 4.1 and then importing it in a recent version when generating thumbs different sizes/urls get created with the same settings, in fact ones which might be off by one pixel. Therefore when those images are used in posts they are broken after import.
For reference I am adding an extensive WPSE question as well as the corresponding ticket #31581 in trac
What is expected?
When importing posts with image in it URLs are updated so the post still shows the image.
What is happening
Those images that get scaled to a different size post 4.1 break as their size and therefore filename might be off by 1 Pixel.
Solutions?
I have created a workaround for the old importer that roughly does this:
- During the import it hooks into
wp_update_attachment_metadataand calculates the scaled image size for all imported images according to the old scaling behaviour. - If there is a mismatch the offending URL is added to an array…
- …which is then at the end used to go through all posts to replace those urls.
The way this is implemented is a bit convoluted due to the way the old importer works. Fact is that there already is a replacement process going on. It would be most effective if this whole repair process would be (optionally) done there too by adding the replacements to XWR_Importer->url_remap.
What I am basically asking before putting work into a PR is if you
- Think this is a thing that should be fixed in the Importer or is a core issue as this e.g. also would happen when recreating thumbnails.
- If you think my general approach is good or you have any thoughts or ideas for improvement before trying a PR.
Oh I have just realized that for now you are totally ignoring resized images leaving the original URLs in. Then I am leaving the above as a note to keep that in mind when building that feature at some point
Related to #53 I think.
Yes kind of. Once resized images in post_content get replaced as well as requested in #53 the issue I described above will become an issue and needs to be considered.
+1
+1