WordPress Batch Import Guide
Comprehensive guide for the WordPress batch import orchestrator script.Overview
Thewp-batch-import.sh script is a master orchestrator that manages the complete WordPress product import workflow with safety checks, rollback capability, and detailed reporting.
Features
- Safety First: Automatic backups before any changes
- Interactive Mode: Step-by-step confirmations
- Dry-Run Mode: Test without making actual changes
- Rollback Capability: Restore from backups if needed
- Progress Tracking: Real-time progress with ETA
- Detailed Logging: Console and file logging
- Email Notifications: Optional email reports
- Error Handling: Comprehensive error handling and recovery
Prerequisites
- WP-CLI installed
- Node.js and npm
- WordPress installation
- WooCommerce REST API keys
- CSV product file
Installation
- Clone or download scripts to
/scripts/directory:
- Configure environment in
.envfile:
Quick Start
Basic Usage
Configuration Helper
Workflow Steps
The script executes the following steps in order:1. Pre-check
- Verify WP-CLI installation
- Check WordPress path
- Validate CSV file
- Test database connection
- Check required dependencies
2. Backup
- Export WordPress database
- Backup uploads metadata
- Store backup with timestamp
- Save backup location for rollback
3. Download Images
- Extract image URLs from CSV
- Download images to temp directory
- Skip existing images
- Track download statistics
4. Generate SEO Content
- Analyze product data
- Generate meta descriptions
- Create SEO-friendly titles
- Optimize product descriptions
5. Update Products
- Match existing products by SKU
- Update product metadata
- Update prices and stock
- Preserve existing data
6. Create Products
- Create new product posts
- Set product categories
- Assign product attributes
- Link product images
7. Verify Import
- Count imported products
- Validate product data
- Check for errors
- Generate import report
Command Line Options
| Option | Description |
|---|---|
--dry-run | Run without making actual changes |
--skip-downloads | Skip image downloads |
--no-verify | Skip import verification |
--non-interactive | Run without confirmations |
--email | Send email notification |
--help | Show help message |
Environment Variables
| Variable | Description | Default |
|---|---|---|
WP_PATH | WordPress installation path | /path/to/wordpress |
WP_USER | WordPress username | admin |
SITE_URL | Site URL | https://drmanhlinhmd.com |
DRY_RUN | Enable dry run mode | false |
SKIP_DOWNLOADS | Skip image downloads | false |
VERIFY | Enable verification | true |
INTERACTIVE | Enable confirmations | true |
EMAIL_NOTIFY | Enable email | false |
EMAIL_TO | Email recipient | [email protected] |
Examples
Test Run (Recommended First Step)
Production Import
Skip Image Downloads
Custom Configuration
Output and Logs
Console Output
The script provides colored console output:- 🟢 Green: Success messages
- 🔴 Red: Error messages
- 🟡 Yellow: Warnings
- 🔵 Blue: Information
- 🟣 Purple: Debug messages
Log Files
Logs are saved to/logs/ directory:
Statistics Report
The final report includes:- Products processed/updated/created/failed
- Images downloaded/failed
- Total errors
- Execution time
- Backup location
Rollback
If the import fails or you need to undo changes:Troubleshooting
WP-CLI Not Found
Permission Denied
Database Connection Error
Image Download Failures
WooCommerce API Errors
CSV File Format
Expected CSV structure:Best Practices
- Always test with dry-run first
- Keep regular backups
- Monitor logs for errors
- Verify imports in WordPress admin
- Use non-interactive mode for automation
- Enable email notifications for production
- Keep CSV file validated and clean
Automation
Cron Job
CI/CD Pipeline
Support
For issues or questions:- Check log files in
/logs/ - Review configuration with
wp-import-config.sh validate - Test with
--dry-runfirst - Check WordPress and WooCommerce requirements