Add ability to prevent remote fetches #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello — Figured I'd open this PR to see if there was any interest. If not, that's okay.
The use case is actually a real-world scenario I'm dealing with right now :)
I've got a site with over 2,000 attachments I'm trying to import into an existing site. To speed things up, I downloaded all the files inside the uploads directory to my local machine via FTP.
I then created an export on the source site (All content + Media) and then started an import on the destination site. Problem is, the destination site still wants to download all the files from the source site even though they already exist locally.
With this PR, a new constant for wp-config.php is introduced (
IMPORT_PREVENT_REMOTE_FETCH
) and when set to true thefetch_remote_file()
function is short-circuited to return an array of info on the locally existing file for the attachment. There is also animport_prevent_remote_fetch
filter that receives the value of the constant, the URL, and the attachment to provide more fine-tuned control.Looking forward to any feedback. Thanks!