DOCS

v1.3.28
 // Pro v1.2.20

 · Latest

Docs/Developer Guide/CLI and Automation

CLI and Automation

Order Daemon Pro provides a WP-CLI interface for rule management, audit log analysis, health monitoring, and configuration management.

CLI commands are exclusively available in Order Daemon Pro. The free Core plugin does not register any CLI commands. If you run wp help odcm and see nothing, ensure the Pro plugin is installed and activated.

Prerequisites

  • WP-CLI installed (wp --info)
  • Order Daemon Pro installed and activated
  • WooCommerce active
  • Appropriate permissions to run wp as the site’s PHP user

Available command groups

Rule management (wp odcm rule)

List rules:

wp odcm rule list [--format=<format>] [--status=<status>]

Options:

  • --format: table (default), json, csv, yaml
  • --status: all (default), active, inactive
# List all rules
wp odcm rule list

# Active rules as JSON
wp odcm rule list --status=active --format=json

# Export for integration
wp odcm rule list --format=csv

Activate a rule:

wp odcm rule activate <rule_id> [--dry-run] [--yes]

Deactivate a rule:

wp odcm rule deactivate <rule_id> [--dry-run] [--yes]
# Interactive activation with confirmation
wp odcm rule activate 123

# Automated  -  CI/CD friendly
wp odcm rule activate 123 --yes

# Preview without making changes
wp odcm rule activate 123 --dry-run

Log management (wp odcm log)

List log entries:

wp odcm log list [--limit=<number>] [--offset=<number>] [--order-id=<id>] [--status=<status>] [--since=<date>] [--format=<format>]

Export audit logs:

wp odcm log export [--format=<format>] [--limit=<limit>] [--order-id=<id>] [--status=<status>] [--since=<date>] [--until=<date>] [--output=<file>]

View a specific entry:

wp odcm log view --id=<log_id> [--format=<format>]

Bulk delete:

wp odcm log bulk-delete [--status=<status>] [--before=<date>] [--order-id=<id>] [--limit=<number>] [--dry-run] [--yes]
# Export last 100 entries as JSON
wp odcm log export --format=json --limit=100

# View a specific log entry
wp odcm log view --id=123

# Export logs for a specific order
wp odcm log export --order-id=456 --format=csv --output=order-logs.csv

# Preview bulk delete
wp odcm log bulk-delete --status=error --dry-run

Health monitoring (wp odcm health)

Full health check:

wp odcm health check [--category=<category>] [--format=<format>] [--exit-code-on-warning] [--exit-code-on-critical]

Options:

  • --category: all (default), core, api, performance, frontend
  • --format: table (default), json, dashboard, summary

Quick status:

wp odcm health status [--format=<format>]
# Basic health check
wp odcm health check

# CI/CD ready JSON output with exit codes
wp odcm health check --format=json --exit-code-on-warning

# Check specific component
wp odcm health check --category=api

Debug commands (wp odcm debug)

Analyze why a rule didn’t trigger:

wp odcm debug why-not --order=<order_id> [--rule=<rule_id_or_name>] [--format=<format>] [--verbose]

Options:

  • --format: rich (default), json, table

Test rule evaluation:

wp odcm debug evaluate --order=<order_id> --rule=<rule_id_or_name> [--format=<format>]
# Analyze why a specific rule didn't trigger
wp odcm debug why-not --order=123 --rule="Complete VIP Orders"

# JSON output for programmatic use
wp odcm debug why-not --order=123 --rule=5 --format=json

Configuration management (wp odcm config)

Export configuration:

wp odcm config export [--output=<file>] [--format=<format>] [--components=<components>] [--exclude-sensitive]

Import configuration:

wp odcm config import <file> [--merge-strategy=<strategy>] [--backup-existing] [--dry-run]

Compare configurations:

wp odcm config diff [--local=<file>] [--components=<components>] [--format=<format>] [--show-values]
# Export only rules to YAML
wp odcm config export --components=rules --format=yaml --output=rules.yaml

# Exclude sensitive data
wp odcm config export --exclude-sensitive --output=template.json

# Import with backup
wp odcm config import template.json --merge-strategy=update --backup-existing

# Preview changes before applying
wp odcm config import client-setup.json --dry-run

# Compare current config with a backup
wp odcm config diff --local=backup.json

Practical workflows

Safe rule development

# 1. List current rules
wp odcm rule list

# 2. Preview activation
wp odcm rule activate 123 --dry-run

# 3. Activate for testing
wp odcm rule activate 123

# 4. Monitor health
wp odcm health check --category=performance

# 5. Check logs
wp odcm log list --limit=10

# 6. Roll back if needed
wp odcm rule deactivate 123 --yes

Production deployment script

#!/bin/bash
# Health check before deployment
wp odcm health check --exit-code-on-warning || exit 1

# Preview changes
wp odcm rule activate 123 --dry-run
wp odcm rule activate 456 --dry-run

# Apply
wp odcm rule activate 123 --yes
wp odcm rule activate 456 --yes

# Verify
wp odcm health check --category=rules --exit-code-on-warning

# Export post-deployment snapshot
wp odcm config export --output="deployment-$(date +%Y%m%d).json"

Daily monitoring cron

# Nightly diagnostics
5 2 * * * cd /var/www/html && wp odcm health check --format=json >> /var/log/odcm-diag.log 2>&1

# Weekly log cleanup
15 2 * * 0 cd /var/www/html && wp odcm log bulk-delete --before="90 days ago" --yes >> /var/log/odcm-cleanup.log 2>&1

Multi-site configuration

# Export template from staging
wp odcm config export --exclude-sensitive --output=site-template.json

# Import on production (preview first)
wp odcm config import site-template.json --dry-run
wp odcm config import site-template.json --merge-strategy=update --backup-existing

Observability and logging

CLI command handlers emit structured audit events using odcm_log_event() so operators can trace results in the Insight timeline. Include process_id in the extra payload to correlate related entries.

  • Use --format=json for machine-readable output in scripts.
  • Use --yes to skip interactive prompts in automated environments.
  • Commands return non-zero exit codes on failure.
  • Respect ODCM_DEBUG for verbose output – avoid enabling in cron.

Security

  • WP-CLI bypasses browser nonces but all commands still respect WordPress capability requirements.
  • Never pass secrets on the command line – use environment variables for tokens.
  • For inbound webhooks, use HMAC signatures and rate limiting, not CLI access.

Troubleshooting

Command not found (wp odcm --help shows nothing): Ensure Order Daemon Pro is installed and activated. Core does not register CLI commands.

WooCommerce inactive: Most commands will fail with an explanatory error.

Permission errors: Run wp as the same system user that owns WordPress files, or use sudo -u www-data wp ....

Exit code non-zero: Check stdout/stderr logs; also review the Insight Dashboard for audit entries emitted by the command handler.

Untranslated output: Confirm the order-daemon text domain is loaded in the environment where wp runs.

Built-in help

# List all Order Daemon commands
wp odcm --help

# Help for specific groups
wp odcm rule --help
wp odcm log --help
wp odcm health --help
wp odcm config --help
wp odcm debug --help