Localize hotlinked images into your media library

MediaIntermediate~15 minUpdated

Before you start

A connected site with content reads on and the media upload ability and Replace block enabled. The images have to be reachable at their current HTTPS URLs on a public host, because the plugin fetches them itself. The link must go straight to the image: a link that redirects is refused. An image URL sits inside an image tag, and the find-and-replace tool refuses anything inside a tag or attribute, so the agent reads the post as raw block markup and rewrites the image block. Pages are reached only while the Update page tool is on. Posts owned by a page builder are refused. The upload tool needs a filename for each image, so the agent picks one from the original name. The image uploads cannot be undone, but each block swap is recorded in the Changes tab.

Hotlinked images are a slow leak. A post shows pictures loaded straight off someone else’s server, and the day that server moves the file, renames it, or blocks the referrer, your post shows a row of broken boxes. You did not do anything wrong, but the page looks abandoned. The fix is to host the images yourself, which by hand means downloading each one, uploading it, and pasting the new URL back in.

This runs that chore for you and still waits for your yes before it saves a thing.

The prompt
[This post: https://example.com/my-post/] pulls its images from other
people's servers, and I want them hosted here instead. Start read-only:
read the post, list every image whose URL points at a domain that is not
mine, and show me that list with nothing changed yet.
Wait for my yes. Only after I approve, go image by image: fetch each
external image into the media library with the upload-from-URL tool (HTTPS
links to jpg, png, gif and webp are fine; SVG and plain http links will be
rejected, so list those for me), then swap that old external URL
for the new local one. A literal find-and-replace will be refused because the
URL sits inside an image tag, so read the post as raw block markup and replace
only the image block, sending exactly one block and passing its path and
core/image as the expected block name, with the new local URL and attachment
id. If an image is not in a block, or its block is not core/image, list it as
skipped. Work in small batches and show me each batch, with the old block
markup beside the new one, before it saves, and leave everything except the
image URLs alone. When you finish, give me the list of every image you pulled
in and every URL you replaced.

Why this is safe to run

The first pass is reads. Reading the post and picking out the off-site image URLs changes nothing, so you approve the exact list before any file is uploaded or any URL is swapped.

The write half is deliberately narrow. The upload-from-URL ability fetches only HTTPS links to public hosts, adds the images to your library and rejects SVG outright, so nothing scriptable sneaks in through an image. The swap is one Replace block call per image block. Replace block checks the block name at that path before it writes, and the old markup is in the reply, so a wrong swap can be put back. The Changes tab can revert a swap unless the post has been edited after it. The uploaded copies stay in your library either way, because uploads are not recorded. As always, the media and content write abilities stay off until you enable them, every call is checked against the bound user’s capability, and every upload and edit is written to the Activity Log.

Already connected? Skip the paste. Ask your agent for the “localize hotlinked images” recipe, or just point it at the post, and it runs the same find-approve-swap flow on your own install.

How it works

  1. Read the post and list every image whose URL points at a domain that is not yours.
  2. Show you that list and wait for approval before anything saves.
  3. Fetch each external HTTPS image into the media library with the upload-from-URL tool.
  4. Replace each image block that uses an old external URL with one that uses the new local URL, in small batches.
  5. Return the list of images pulled in and every URL it changed.

Questions

What image types can it bring in?
The upload ability accepts jpg, png, gif, and webp, fetched from an HTTPS link. SVG is rejected on purpose, so an SVG hotlink is reported but left in place for you to handle by hand, and so is any plain http link.
Does it change anything besides the image URLs?
No. It replaces only the image blocks that point at an external URL, passing each block's path and core/image as the expected block name, and shows you the old markup with every batch. The plugin leaves the other blocks' parsed attributes and HTML as they were.