A treat for site migrators and people with loads of remotely hosted images that need to be imported into a WordPress site. Import External Images 2, the VR51 edition, is our latest WordPress plugin.
Our plugin is based on code released by Marty Thornley. Marty’s Import External Images plugin was in need of maintenance. We stepped up to the plate to fork the code and upgrade the plugin.
In a nutshell, Import External Images VR51 will scan all posts and all pages to look for any images that are hosted on an external server. The plugin will offer to import those images into your own WordPress media library. The image links within any affected posts or pages are then updated to point to the locally hosted file.
This plugin is useful mainly to people who have hotlinked someone else’s images or moved a website from Blogger or WordPress.com to a self hosted WordPress site.
The plugin download link is at the bottom of this post.
How Import External Images Works
The plugin has two modes of operation:
- Use it within the post/page editor screen to import externally hosted files one article at a time, or
- Use it to bulk import externally hosted files by visiting the plugin’s admin page at Media > Import Images.
Import External Images follows a simple routine:
- Scan posts and pages for any external image files and PDF files
- Download any external files
- Update the URL of the file to point to the downloaded copy
The plugin scans for PNG, JPG, JPEG, GIF, BMP and PDF files. Other file types are not currently supported. We will consider requests (links to WP Service Masters) to add new file types.
Why do I need Import External Images?
You will want to use this plugin if your site displays images that are hosted on another website and you want to host them locally.
You might want to host all images locally because you are worried the 3rd party image host is about to go offline or because you are worried the 3rd party site will change the image or delete it.
You host images on Photobucket and wish to cancel your service subscription so need to download your images to your own website.
What Happened to the Original Plugin?
Faults in the plugin showed over the years. The maintainer of the original plugin code stopped offering support and stopped releasing bug fixes several years ago. We needed to use the plugin for our own purposes so we opted to fix the code.
What is different between the old plugin and the new plugin?
The new plugin will collect files from both HTTP and HTTPS resources. The old plugin could only fetch images from HTTP resources (no S).
The new plugin has a new options screen where you can select the number of images to fetch per post each plugin run and the number of articles to process each plugin run. This allows you to configure the plugin to work better within host environments with tight PHP resource allowances.
The old plugin had hardcoded limits set for the number of posts and images to process each run. These hardcoded limits were ignored by the original plugin code’s bulk updater. We fixed that.
The core code has been updated to remove silent errors in the code such as undeclared variables.
Redundant code has been removed from the plugin.
The new plugin uses fewer files. We merged two files to simplify the code structure. We replaced the plugin’s own spinner.gif image with the WordPress core loading.gif image.
There new plugin has a number of improvements over the old plugin.
What are the plugin options?
The options page allows you to,
- Set the number of files to import and external links to process per post/page (1 to 20).
- Set the number of posts and pages to process per file import run (1 to 50).
- Set which domains the plugin should ignore when fetching for external files to process.
- View a list of posts and pages that contain external image and PDF files.
Why do imports stop early?
Imports stop prematurely if the web server times out before the import process has completed.
Login to your web server and adjust the PHP settings to improve server performance. If you use cPanel, after login,
- Search for Select PHP Version and click the button when it appears.
- In the PHP settings screen, click the link ‘Switch to PHP Options‘
- Increase the values for max_execution_time, memory_limit, post_max_size and upload_max_size. Set them to 600, 192, 128 and 128, respectively. The value for max_input_time should be set to -1. Save the new values.
If you change the PHP version to 7.1 or 7.2 (remember to click ‘Set as Default’) you will get better server performance. You will need to adjust the PHP options again if you change the PHP version. If your website fails to work with PHP 7.1 or 7.2 because of an old plugin or theme, just switch back to PHP 5.6.
Why do I get a white screen?
This happens when the web server times out early. See the answer to the question ‘Why do imports stop early?’ for the solution.
How to use Import External Images
- Download the plugin from Github.
- Install the new plugin via the WordPress Dashboard > Plugins > Add New.
- Activate the plugin.
Visit the plugin’s options page at Media > Import Images to configure the plugin and to view articles that contain externally hosted files.
- Bulk import external images and PDFs from the options page by clicking the Import Images button, or
- Import files into each post individually by clicking the edit post link next to each post shown in the Import Images page.
Any page or post that contains externally hosted image files or PDF files will now display an Image Import metabox below the Publish metabox near the top right of the editor screen. Select the option to import files where image files are shown ready for import.
The number shown next to posts in the import table and within the import metabox in the editor screen tells the number of links to be processed. This is not the same number as the number of externally hosted files. The plugin counts together both the number of remotely hosted files and their associated hyper-links. Run the import process as many times as required until this number reaches zero otherwise you may end up with imported files that still link to their external locations.
Adjust the plugin options to improve the file download experience on low resource web servers.
Use Import External Images 2 when you have a ton of image and PDF files in your content but those files are hosted on a 3rd party service and you need to automatically download those files to your own server and to automatically relink to the locally hosted files.
Questions, Suggestions and Tips?
Comment below or raise an issue on Github.