WP-CLI Integration
FreshMainWP provides WP-CLI commands for managing your Dashboard from the command line.
Prerequisites
- WP-CLI installed on the Dashboard server
- MainWP Dashboard plugin activated
- WordPress accessible via WP-CLI (
wp --infoworks)
Available Commands
Site Management
bash
# List all connected sites
wp mainwp sites list
# Get site details
wp mainwp sites get --site-id=123
# Sync a specific site
wp mainwp sites sync --site-id=123
# Sync all sites
wp mainwp sites sync --all
# Add a new site
wp mainwp sites add --url="https://example.com" --admin="admin"
# Remove a site
wp mainwp sites remove --site-id=123 --forceUpdate Management
bash
# List available updates
wp mainwp updates list
# List updates for a specific site
wp mainwp updates list --site-id=123
# Update all plugins on a site
wp mainwp updates plugins --site-id=123
# Update all themes on a site
wp mainwp updates themes --site-id=123
# Update WordPress core on a site
wp mainwp updates core --site-id=123
# Update everything on all sites
wp mainwp updates allClient Management
bash
# List clients
wp mainwp clients list
# Add a client
wp mainwp clients add --name="Acme Corp" --email="info@acme.com"
# Suspend a client
wp mainwp clients suspend --client-id=5Extension Management
bash
# List installed extensions
wp mainwp extensions list
# Activate an extension
wp mainwp extensions activate --slug="mainwp-sucuri-extension"
# Deactivate an extension
wp mainwp extensions deactivate --slug="mainwp-sucuri-extension"Output Formats
All list commands support output format flags:
bash
# Table (default)
wp mainwp sites list --format=table
# JSON
wp mainwp sites list --format=json
# CSV
wp mainwp sites list --format=csv
# YAML
wp mainwp sites list --format=yaml
# Count only
wp mainwp sites list --format=countScripting Examples
Sync and Update All Sites
bash
#!/bin/bash
# Sync all sites, then apply updates
wp mainwp sites sync --all
sleep 30
wp mainwp updates all --yesExport Site List
bash
# Export all sites as CSV
wp mainwp sites list --format=csv > sites-export.csvCron Integration
bash
# Add to crontab for automated daily sync
0 2 * * * cd /var/www/dashboard && wp mainwp sites sync --all --quietConditional Updates
bash
#!/bin/bash
# Only update if updates are available
UPDATES=$(wp mainwp updates list --format=count)
if [ "$UPDATES" -gt "0" ]; then
echo "Found $UPDATES updates. Applying..."
wp mainwp updates all --yes
else
echo "No updates available."
fiEnvironment Variables
| Variable | Description |
|---|---|
WP_CLI_CONFIG_PATH | Path to WP-CLI config file |
WP_CLI_DISABLE_AUTO_CHECK_UPDATE | Disable WP-CLI self-update checks |
WP_CLI_STRICT_ARGS_MODE | Enforce strict argument parsing |
Troubleshooting
| Issue | Fix |
|---|---|
| "MainWP not found" | Ensure MainWP Dashboard plugin is activated |
| Permission denied | Run as the WordPress file owner, not root |
| Timeout on sync | Increase max_execution_time in PHP config |
| Memory error | Increase memory_limit in PHP config |
| SSL errors | Add --skip-ssl-verify flag (dev only) |