Skip to content

WP-CLI Integration

Fresh

MainWP 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 --info works)

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 --force

Update 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 all

Client 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=5

Extension 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=count

Scripting 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 --yes

Export Site List

bash
# Export all sites as CSV
wp mainwp sites list --format=csv > sites-export.csv

Cron Integration

bash
# Add to crontab for automated daily sync
0 2 * * * cd /var/www/dashboard && wp mainwp sites sync --all --quiet

Conditional 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."
fi

Environment Variables

VariableDescription
WP_CLI_CONFIG_PATHPath to WP-CLI config file
WP_CLI_DISABLE_AUTO_CHECK_UPDATEDisable WP-CLI self-update checks
WP_CLI_STRICT_ARGS_MODEEnforce strict argument parsing

Troubleshooting

IssueFix
"MainWP not found"Ensure MainWP Dashboard plugin is activated
Permission deniedRun as the WordPress file owner, not root
Timeout on syncIncrease max_execution_time in PHP config
Memory errorIncrease memory_limit in PHP config
SSL errorsAdd --skip-ssl-verify flag (dev only)