Drupal Gallery Importer
Import Drupal galleries from JSON into a custom post type, with background processing, batched imports, live progress, and multiple front-end displays including tiles with lightbox. Handles large gallery deletions without timeouts.
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/nikoicarl/drupal-gallery-importer/archive/refs/heads/main.zipDrupal Gallery Importer for WordPress
A robust WordPress plugin that imports Drupal galleries from JSON format into a custom post type with background processing, batch imports, and multiple display options.
🎯 Features
Core Functionality
- JSON Import: Import galleries from Drupal JSON exports
- Background Processing: Automatic background processing for large imports
- Batch Management: Process galleries in configurable batches to prevent timeouts
- Image Downloads: Automatically download and import images to WordPress media library
- Progress Tracking: Real-time progress monitoring with pause/resume/stop controls
- Smart Duplicate Detection: Skip existing galleries based on Drupal NID
Gallery Management
- Custom Post Type: Dedicated
gallerypost type with full WordPress support - Taxonomy Support:
gallery_typetaxonomy for organizing galleries - Meta Storage: Preserves Drupal NID and original links
- Sortable Images: Drag-and-drop image ordering in admin
- Media Library Integration: Full WordPress media library support
Display Options
- Auto Display: Galleries automatically append to single gallery pages
- Shortcodes: Multiple shortcode options for flexible display
- Responsive Grid: Mobile-friendly responsive layouts
- Lightbox: Built-in lightbox for image viewing
- Customizable Columns: 1-6 column layouts
Performance & Safety
- Memory Management: Smart memory monitoring and allocation
- Timeout Protection: Automatic background processing for large files
- Optimized Deletion: Background processing for galleries with 30+ images
- Orphan Protection: Only deletes images not used elsewhere
- Cache Management: Intelligent cache clearing during processing
📋 Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher
- MySQL 5.6 or higher
- PHP extensions:
json,curl,gdorimagick
🚀 Installation
Manual Installation
- Download the plugin files
- Upload to
/wp-content/plugins/drupal-gallery-importer/ - Activate through WordPress admin → Plugins
- Navigate to Galleries → Import to begin
Via WordPress Admin
- Go to Plugins → Add New
- Upload the plugin ZIP file
- Click "Install Now" then "Activate"
📖 Usage
Importing Galleries
-
Navigate to Galleries → Import
-
Upload your JSON file
-
Configure import options:
- Drupal Site URL: Base URL for image downloads
- Skip Existing: Avoid duplicate imports
- Download Images: Import images to media library
- Background Processing: Recommended for large imports
-
Click "Import Galleries"
-
Monitor progress in real-time
JSON Format
{
"items": [
{
"nid": 8821,
"title": "Summer Gallery 2024",
"description": "Beautiful summer photos",
"summary": "A collection of summer memories",
"publish_date": "2024-06-15 10:30:00",
"link": "/gallery/summer-2024",
"gallery_types": [
{ "name": "Events" },
{ "name": "Seasonal" }
],
"images": [
"/sites/default/files/gallery/image1.jpg",
"/sites/default/files/gallery/image2.jpg"
]
}
]
}
Shortcodes
Single Gallery Display
[gallery_display id="123" columns="4" size="medium" lightbox="yes"]
Parameters:
id- Gallery post ID (default: current post)columns- Number of columns 1-6 (default: 3)size- Image size (default: medium)lightbox- Enable lightbox yes/no (default: yes)
Gallery Index with Pagination
[gallery_index_lightbox per_page="24" columns="4" size="large" show_titles="yes" orderby="date" order="DESC"]
Parameters:
per_page- Galleries per page (default: 24)columns- Grid columns 1-6 (default: 4)size- Thumbnail size (default: large)show_titles- Display titles yes/no (default: yes)orderby- Sort field (default: date)order- ASC or DESC (default: DESC)new_tab- Open in new tab yes/no (default: no)
🎨 Customization
Filters
// Modify gallery columns on single pages
add_filter('dgi_gallery_columns', function($columns) {
return 5; // Return 1-6
});
// Force asset loading on specific pages
add_filter('dgi_force_assets', function($force) {
return is_page('galleries');
});
Styling
The plugin includes responsive CSS that can be overridden in your theme:
/* Override gallery grid */
.nu-gallery-grid {
gap: 20px;
}
/* Customize gallery items */
.nu-gallery-item {
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
⚙️ Configuration
Import Settings
Configure in Galleries → Import:
- Batch Size: Number of galleries per batch (default: 5)
- Image Batch Size: Images processed per cycle (default: 3)
- Max Processing Time: Seconds per batch (default: 15)
- Download Timeout: Image download timeout (default: 45s)
Deletion Settings
Configure in Galleries → Settings:
- Delete Images: Remove orphaned images on gallery deletion
- Delete Terms: Remove unused gallery type terms
- Background Threshold: Galleries with 30+ images process in background
🔧 Advanced Features
Background Processing
Large imports automatically use background processing:
- Files over 3MB
- Insufficient memory detected
- Image downloads enabled
Job Management
Monitor and control import jobs in Galleries → Import Jobs:
- View all import jobs
- Check job status
- Access detailed logs
- View processing history
Diagnostic Tools
Built-in NID checker helps prevent duplicates:
- Enter Drupal NID
- Check if gallery exists
- View existing gallery if found
Progress Controls
Real-time job controls during import:
- Pause: Temporarily halt processing
- Resume: Continue paused jobs
- Stop: Cancel import job
- Live Updates: Real-time progress tracking
🗑️ Gallery Deletion
Smart deletion protects shared resources:
Images
- Only deletes if not used in other galleries
- Checks featured image usage
- Background processing for 30+ images
- Prevents timeout errors
Gallery Types
- Only deletes if no other galleries use the term
- Automatic cleanup of orphaned terms
- Configurable via settings
🐛 Troubleshooting
Import Fails
Issue: Import stops or fails
Solution:
- Enable background processing
- Increase PHP
memory_limitto 512M - Check PHP error logs
- Verify JSON format
Images Not Downloading
Issue: Images fail to download
Solution:
- Check Drupal site URL is correct
- Verify images are publicly accessible
- Increase
DGI_DOWNLOAD_TIMEOUTconstant - Check server firewall settings
Timeout Errors
Issue: Page times out during import
Solution:
- Background processing auto-enables for large files
- Reduce
DGI_BATCH_SIZEconstant - Increase PHP
max_execution_time - Use WP-CLI for very large imports
Duplicate Galleries
Issue: Galleries import multiple times
Solution:
- Enable "Skip existing" option
- Use NID checker tool before import
- Check for duplicate NIDs in JSON
📊 Performance Tips
For Large Imports
- Enable Background Processing: Always recommended
- Increase PHP Limits:
memory_limit = 512M max_execution_time = 300 - Use Cron: Ensure WP-Cron is working
- Monitor Logs: Check import logs for issues
- Batch Processing: Let the plugin handle batching automatically
For Image-Heavy Galleries
- Enable Image Downloads: Plugin optimizes automatically
- Configure Timeouts: Adjust
DGI_DOWNLOAD_TIMEOUTif needed - Server Resources: Ensure adequate bandwidth and storage
- Background Jobs: Large galleries auto-process in background
🔌 Constants Reference
Override these in wp-config.php:
// Batch processing
define('DGI_BATCH_SIZE', 5); // Galleries per batch
define('DGI_IMAGE_BATCH_SIZE', 3); // Images per batch
define('DGI_MAX_SECONDS', 15); // Max processing time
// File handling
define('DGI_UPLOAD_DIR', 'dgi-imports');
define('DGI_FILE_SIZE_FALLBACK', 3 * 1024 * 1024); // 3MB
// Network
define('DGI_DOWNLOAD_TIMEOUT', 45); // Image download timeout
// Display
define('DGI_DEFAULT_COLUMNS', 3); // Default grid columns
📝 Changelog
Version 2.5.0
- Added background image deletion for large galleries
- Improved orphan detection for images and terms
- Enhanced deletion settings interface
- Optimized database queries with caching
- Added NID diagnostic tool
- Improved progress tracking and controls
Version 2.0.0
- Complete background processing system
- Real-time progress monitoring
- Job pause/resume/stop controls
- Batch processing optimization
- Enhanced memory management
Version 1.0.0
- Initial release
- Basic JSON import functionality
- Gallery custom post type
- Simple shortcode support
🤝 Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
📄 License
This plugin is licensed under the GPL v2 or later.
Copyright (C) 2024 Carl Nikoi
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
👨💻 Author
Carl Nikoi
🙏 Acknowledgments
- WordPress community for best practices
- Drupal migration community for insights
- Contributors and testers
📞 Support
- Issues: GitHub Issues
- Documentation: Wiki
- WordPress: Support Forum
🔮 Roadmap
- [ ] WP-CLI commands for bulk operations
- [ ] REST API endpoints
- [ ] Multi-site support
- [ ] Advanced image optimization
- [ ] Export functionality
- [ ] Gallery templates system
- [ ] Gutenberg blocks
Made with ❤️ for seamless Drupal to WordPress migrations