Not sure if this makes sense but I’m trying to attach hotlinked images to their posts/pages with no lucky, most plugins such Cache images works ok but only to external domains, I need to auto-attach hotlinked images in the same domain/server.
Addendum: This happened duo copying-pasting content from static html files into WP pages and posts.
Thanks for any clue!
No complete code, but I know you can stick it together. 🙂
Find all post IDs of unattached images (borrowed from
wp-admin/upload.php
):Get image URLs for all post IDs: Since these attachments have no parent their URL is equivalent to
get_the_guid()
(that’s one of the two reasons the GUID looks like an URL, I don’t like that).Now find posts with those images and attach the images to these posts:
Not tested, see it just as hints.
Thanks @toscho, I think I figured how your code can work (that can take time hahah), firstly import images files within server (Add form server plugin can do this or can use a custom script), find image paths within every post/page that match filenames now in media library, then attach them.
I can’t use this because there where different imagens but same filenames along different folders (also some problems with filenames using spaces), then I had to use this plugin, you must visit/edit every page/post and download the images, that can be a pain but at least will work with files wherever they are (same doamin for example), surely there is someway to hack this plugin to work on every post on page.
(If image filenames has spaces this plugin still will return empty images and you need to re-edit it manually, don’t know why WP can diplay hotlinked images with strange filenames)