WP-CLI Commands
Virtual Media Folders AI Organizer provides a comprehensive WP-CLI interface for automating media organization via the command line.
Prerequisites
Section titled “Prerequisites”- Virtual Media Folders plugin must be installed and activated
- An AI provider must be configured (via settings, constants, or CLI parameters)
Quick Start
Section titled “Quick Start”# 1. Start a preview scan of unassigned mediawp vmfa-ai scan start
# 2. Monitor progress with live updates (runs Action Scheduler queue)wp vmfa-ai scan status --watch
# 3. Review the resultswp vmfa-ai scan results
# 4. Apply the changeswp vmfa-ai scan applyNote: The
--watchoption automatically runs the Action Scheduler queue, so scans will process while you watch. Without--watch, you need to ensure the WordPress cron or Action Scheduler is running.
Commands Reference
Section titled “Commands Reference”Scan Commands
Section titled “Scan Commands”wp vmfa-ai scan start
Section titled “wp vmfa-ai scan start”Start a new media scan in preview mode. Uses Action Scheduler for background processing.
wp vmfa-ai scan start [--mode=<mode>] [--provider=<provider>] [--model=<model>] [--api-key=<key>] [--endpoint=<url>] [--timeout=<seconds>] [--porcelain]Options:
| Option | Description | Default |
|---|---|---|
--mode | Scan mode: organize_unassigned, reanalyze_all, or reorganize_all | organize_unassigned |
--provider | Override AI provider (openai, anthropic, gemini, ollama, grok, exo) | Configured provider |
--model | Override AI model | Provider default |
--api-key | Override API key | Configured key |
--endpoint | Override endpoint URL (for ollama/exo) | Configured endpoint |
--timeout | Request timeout in seconds | Provider default |
--porcelain | Machine-readable output | false |
Scan Modes:
| Mode | Description |
|---|---|
organize_unassigned | Only analyze media not already in folders |
reanalyze_all | Re-analyze all media (keeps existing folder structure) |
reorganize_all | Delete all folders and rebuild from scratch |
Examples:
# Scan unassigned media using configured providerwp vmfa-ai scan start
# Scan all media with a specific provider/modelwp vmfa-ai scan start --mode=reanalyze_all --provider=ollama --model=llava:34b
# Full reorganization (warning: deletes existing folders)wp vmfa-ai scan start --mode=reorganize_all
# Override for one-time testwp vmfa-ai scan start --provider=openai --api-key=sk-xxx --model=gpt-4owp vmfa-ai scan status
Section titled “wp vmfa-ai scan status”Show current scan status and progress.
wp vmfa-ai scan status [--watch] [--format=<format>] [--porcelain]Options:
| Option | Description | Default |
|---|---|---|
--watch | Continuously monitor with live updates | false |
--format | Output format: table, json, yaml | table |
--porcelain | Machine-readable output: status:processed:total | false |
Examples:
# Check current statuswp vmfa-ai scan status
# Watch with live updates (refreshes every 2 seconds)wp vmfa-ai scan status --watch
# Get status as JSON for scriptingwp vmfa-ai scan status --format=jsonLive Watch Display:
When using --watch, you’ll see a live-updating display with:
- Progress bar with percentage
- Elapsed time and ETA
- Real-time results table showing recent AI suggestions
- Color-coded confidence levels (green ≥80%, yellow ≥50%, red <50%)
Important: The
--watchoption is designed for interactive terminal use only. It automatically runs pending Action Scheduler tasks while displaying live progress. For scripts or background automation, use--porcelainto poll status instead (see Scripting Example below).
wp vmfa-ai scan apply
Section titled “wp vmfa-ai scan apply”Apply the previewed scan results.
wp vmfa-ai scan apply [--yes] [--porcelain]Options:
| Option | Description |
|---|---|
--yes | Skip confirmation prompt |
--porcelain | Machine-readable output |
Examples:
# Apply with confirmation promptwp vmfa-ai scan apply
# Skip confirmation (for scripts)wp vmfa-ai scan apply --yeswp vmfa-ai scan cancel
Section titled “wp vmfa-ai scan cancel”Cancel a running scan.
wp vmfa-ai scan cancel [--porcelain]wp vmfa-ai scan reset
Section titled “wp vmfa-ai scan reset”Reset scan progress to idle state. Use if the scan appears stuck.
wp vmfa-ai scan reset [--yes] [--porcelain]wp vmfa-ai scan results
Section titled “wp vmfa-ai scan results”Display cached preview results.
wp vmfa-ai scan results [--format=<format>] [--porcelain]Options:
| Option | Description | Default |
|---|---|---|
--format | Output format: table, json, csv, yaml | table |
--porcelain | Output only attachment IDs | false |
Single Media Analysis
Section titled “Single Media Analysis”wp vmfa-ai analyze <attachment_id>
Section titled “wp vmfa-ai analyze <attachment_id>”Analyze a single media attachment.
wp vmfa-ai analyze <attachment_id> [--apply] [--provider=<provider>] [--model=<model>] [--api-key=<key>] [--endpoint=<url>] [--format=<format>] [--porcelain]Options:
| Option | Description |
|---|---|
<attachment_id> | The WordPress attachment ID to analyze (required) |
--apply | Apply the suggested folder immediately |
--provider | Override AI provider |
--model | Override AI model |
--format | Output format: table, json, yaml |
--porcelain | Machine-readable output |
Examples:
# Analyze attachment 123 (preview only)wp vmfa-ai analyze 123
# Analyze and apply immediatelywp vmfa-ai analyze 123 --apply
# Test with a different providerwp vmfa-ai analyze 123 --provider=anthropic --model=claude-3-5-sonnet-latest
# Get JSON outputwp vmfa-ai analyze 123 --format=jsonBackup Commands
Section titled “Backup Commands”wp vmfa-ai backup <action>
Section titled “wp vmfa-ai backup <action>”Manage folder structure backups.
wp vmfa-ai backup <action> [--yes] [--format=<format>] [--porcelain]Actions:
| Action | Description |
|---|---|
export | Create a backup of current folder structure and assignments |
info | Show information about the existing backup |
restore | Restore folders and assignments from backup |
delete | Delete the stored backup |
Examples:
# Create a backup before making changeswp vmfa-ai backup export
# Check backup infowp vmfa-ai backup info
# Restore from backup (with confirmation)wp vmfa-ai backup restore
# Restore without confirmationwp vmfa-ai backup restore --yes
# Delete backupwp vmfa-ai backup delete --yesProvider Commands
Section titled “Provider Commands”wp vmfa-ai provider <action>
Section titled “wp vmfa-ai provider <action>”Manage and test AI providers.
wp vmfa-ai provider <action> [--provider=<provider>] [--model=<model>] [--api-key=<key>] [--endpoint=<url>] [--format=<format>] [--porcelain]Actions:
| Action | Description |
|---|---|
list | Show all available providers with their configuration status |
test | Test connection to the configured (or specified) provider |
info | Show detailed info about the current provider |
Examples:
# List all providerswp vmfa-ai provider list
# Test the configured providerwp vmfa-ai provider test
# Test a specific providerwp vmfa-ai provider test --provider=ollama --endpoint=http://192.168.1.100:11434
# Get current provider infowp vmfa-ai provider infoStatistics
Section titled “Statistics”wp vmfa-ai stats
Section titled “wp vmfa-ai stats”Show media library statistics.
wp vmfa-ai stats [--format=<format>] [--porcelain]Examples:
# Show statswp vmfa-ai stats
# Get stats as JSONwp vmfa-ai stats --format=jsonOutput includes:
- Total media count
- Assigned media count
- Unassigned media count
- Number of folders
- Organization percentage with progress bar
Global Options
Section titled “Global Options”These options work with all commands:
| Option | Description |
|---|---|
--porcelain | Minimal machine-readable output for scripting |
--format=<format> | Output format where applicable |
--no-color | Disable colored output (WP-CLI built-in) |
--quiet | Suppress informational messages (WP-CLI built-in) |
Configuration Priority
Section titled “Configuration Priority”When using CLI parameters, the configuration priority is:
- CLI parameters (
--provider,--model,--api-key,--endpoint) - PHP constants (
VMFA_AI_PROVIDER,VMFA_AI_OPENAI_KEY, etc.) - Environment variables (
VMFA_AI_PROVIDER, etc.) - Database settings (configured via admin UI)
- Defaults
This allows you to temporarily override settings for testing without changing your configuration.
Workflow Examples
Section titled “Workflow Examples”Complete Organization Workflow
Section titled “Complete Organization Workflow”# 1. Check current statisticswp vmfa-ai stats
# 2. Create a backup firstwp vmfa-ai backup export
# 3. Test your AI providerwp vmfa-ai provider test
# 4. Start the scan (preview mode)wp vmfa-ai scan start --mode=organize_unassigned
# 5. Monitor progress (runs Action Scheduler automatically)wp vmfa-ai scan status --watch
# 6. Review resultswp vmfa-ai scan results
# 7. If satisfied, applywp vmfa-ai scan apply --yes
# 8. Verify final statisticswp vmfa-ai statsScripting Example
Section titled “Scripting Example”#!/bin/bash
# Automated media organization script
# Check if VMF is activeif ! wp vmfa-ai stats --porcelain > /dev/null 2>&1; then echo "Error: Virtual Media Folders not active" exit 1fi
# Get unassigned countSTATS=$(wp vmfa-ai stats --porcelain)UNASSIGNED=$(echo $STATS | cut -d: -f3)
if [ "$UNASSIGNED" -eq 0 ]; then echo "No unassigned media to process" exit 0fi
echo "Processing $UNASSIGNED unassigned media items..."
# Create backupwp vmfa-ai backup export
# Start scanwp vmfa-ai scan start --mode=organize_unassigned
# Wait for completion (use --watch or run Action Scheduler manually)# Option 1: Use watch which runs the queue automatically# wp vmfa-ai scan status --watch
# Option 2: Poll status while running Action Scheduler separatelywhile true; do STATUS=$(wp vmfa-ai scan status --porcelain) STATE=$(echo $STATUS | cut -d: -f1)
if [ "$STATE" = "completed" ]; then break elif [ "$STATE" = "cancelled" ] || [ "$STATE" = "idle" ]; then echo "Scan ended unexpectedly: $STATE" exit 1 fi
sleep 5done
# Apply resultswp vmfa-ai scan apply --yes
echo "Organization complete!"wp vmfa-ai statsTesting Different Providers
Section titled “Testing Different Providers”# Test with OpenAIwp vmfa-ai analyze 123 --provider=openai --model=gpt-4o
# Test with Anthropicwp vmfa-ai analyze 123 --provider=anthropic --model=claude-3-5-sonnet-latest
# Test with local Ollamawp vmfa-ai analyze 123 --provider=ollama --endpoint=http://localhost:11434 --model=llava:13b
# Compare resultsfor provider in openai anthropic ollama; do echo "=== $provider ===" wp vmfa-ai analyze 123 --provider=$provider --format=json | jq '.folder_name, .confidence'doneTroubleshooting
Section titled “Troubleshooting”Scan appears stuck
Section titled “Scan appears stuck”# Check statuswp vmfa-ai scan status
# Reset if neededwp vmfa-ai scan reset --yes
# Restartwp vmfa-ai scan startProvider connection issues
Section titled “Provider connection issues”# Test provider connectionwp vmfa-ai provider test
# Test with verbose outputwp vmfa-ai provider test --debugView Action Scheduler jobs
Section titled “View Action Scheduler jobs”# List pending VMFA actionswp action-scheduler action list --group=vmfa-ai-organizer --status=pending
# Run pending actions manuallywp action-scheduler run --group=vmfa-ai-organizerExit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error (missing dependencies, failed operation, etc.) |
Related Documentation
Section titled “Related Documentation”📦 Source: soderlind/vmfa-ai-organizer · Edit on GitHub