Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/creativehassan/remote-image-fetcher/archive/refs/heads/main.zipRemote Image Fetcher WordPress Plugin
A WordPress plugin that allows you to fetch images from remote WordPress sites by Image ID with configurable server URL.
Features
- Configurable Remote Server: Set up any WordPress site URL in plugin settings
- Media Library Integration: Fetch images directly from the WordPress Media Library
- Image ID Column: New column in Media Library showing Image ID input and fetch button
- Complete Metadata Import: Imports title, alt text, caption, and description
- WebP to JPG Conversion: Automatically converts WebP images to JPG format (configurable)
- Test Functionality: Built-in test feature to verify remote server connectivity
- Error Handling: Comprehensive error handling and user feedback
Installation
- Upload the
remote-image-fetcherfolder to your/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Go to Settings > Remote Image Fetcher to configure the plugin
Configuration
Plugin Settings
Navigate to Settings > Remote Image Fetcher in your WordPress admin:
- Remote Server URL: Enter the base URL of the remote WordPress site (e.g.,
https://www.cme-online.nl/) - Auto Convert WebP to JPG: Enable/disable automatic WebP to JPG conversion
- Test Image Fetch: Use the test section to verify connectivity with a sample Image ID
Default Configuration
- Default remote URL:
https://www.cme-online.nl/ - WebP conversion: Enabled by default
Usage
Fetching Images from Media Library
- Go to Media > Library in your WordPress admin
- You'll see a new column called "Remote Image ID"
- In any row, enter the Image ID from the remote server
- Click the "Fetch" button
- The plugin will:
- Fetch the image metadata from the remote server
- Download the image to your local media library
- Import all metadata (title, alt text, caption, description)
- Show success/error status
Using in Code
You can also use the plugin's functionality programmatically:
// Get the plugin instance
$rif = new RemoteImageFetcher();
// Fetch a remote image by ID
$result = $rif->fetch_remote_image(123, 0); // Image ID 123, no post attachment
if (!is_wp_error($result)) {
$media_id = $result['media_id'];
$title = $result['title'];
$alt_text = $result['alt_text'];
$imported_url = $result['imported_url'];
echo "Image imported with ID: " . $media_id;
}
Bulk Import Example
// Example of bulk importing images
$image_ids = [123, 456, 789];
$post_id = 0; // Or specific post ID to attach to
foreach ($image_ids as $image_id) {
$result = $rif->fetch_remote_image($image_id, $post_id);
if (!is_wp_error($result)) {
echo "Imported image ID: " . $image_id . " as media ID: " . $result['media_id'] . "\n";
} else {
echo "Failed to import image ID: " . $image_id . " - " . $result->get_error_message() . "\n";
}
}
API Endpoint
The plugin fetches images using the WordPress REST API endpoint:
{REMOTE_URL}/wp-json/wp/v2/media/{IMAGE_ID}
Imported Metadata
The plugin imports the following metadata from remote images:
- Title: Image title
- Alt Text: Alternative text for accessibility
- Caption: Image caption
- Description: Image description
- Source URL: Original image URL
- Remote Reference: Stores remote image ID and URL for reference
Error Handling
The plugin handles various error scenarios:
- Network Errors: Connection timeouts, DNS failures
- HTTP Errors: 404 (image not found), 403 (access denied), etc.
- Invalid Data: Missing image URL, corrupted response
- Import Errors: File download failures, WordPress media import issues
Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher
wp_remote_get()function available (standard WordPress)media_sideload_image()function (standard WordPress)
Security
- AJAX requests are protected with WordPress nonces
- User capability checks ensure only authorized users can fetch images
- Input sanitization and validation
- Secure HTTP requests with proper headers
Troubleshooting
Common Issues
-
"Failed to fetch remote image"
- Check if the remote URL is correct and accessible
- Verify the remote site has the WordPress REST API enabled
- Check if the Image ID exists on the remote server
-
"HTTP Error: 404"
- The Image ID doesn't exist on the remote server
- Try testing with a known valid Image ID
-
"Failed to import image"
- Check WordPress file permissions
- Verify sufficient disk space
- Check if the image URL is accessible
Testing Connectivity
Use the test feature in plugin settings:
- Go to Settings > Remote Image Fetcher
- Enter a known Image ID in the test section
- Click "Test Fetch" to verify connectivity
Changelog
Version 1.0.0
- Initial release
- Basic image fetching functionality
- Media library integration
- Settings page with test functionality
- WebP to JPG conversion
- Complete metadata import
Support
For support and feature requests, please contact the plugin developer.
License
This plugin is licensed under the GPL v2 or later.