Files
WooNooW/WP_CLI_GUIDE.md

7.3 KiB

WP-CLI Usage Guide for WooNooW with Local WP

Installation Complete

WP-CLI has been successfully installed via Homebrew:

  • Version: 2.12.0
  • Location: /usr/local/bin/wp
  • Installed: November 5, 2025

🚀 Quick Start

Basic Usage

# From plugin directory
wp [command] --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Or use the helper script
./wp-cli-helper.sh [command]

Common Commands for WooNooW Development

1. Flush Navigation Cache

# Delete navigation tree cache (forces rebuild)
wp option delete wnw_nav_tree --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Or with helper
./wp-cli-helper.sh option delete wnw_nav_tree

2. Check Plugin Status

# List all plugins
wp plugin list --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Check WooNooW status
wp plugin status woonoow --path="/Users/dwindown/Local Sites/woonoow/app/public"

3. Activate/Deactivate Plugin

# Deactivate
wp plugin deactivate woonoow --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Activate
wp plugin activate woonoow --path="/Users/dwindown/Local Sites/woonoow/app/public"

4. Clear All Caches

# Flush object cache
wp cache flush --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Flush rewrite rules
wp rewrite flush --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Clear transients
wp transient delete --all --path="/Users/dwindown/Local Sites/woonoow/app/public"

5. Database Operations

# Export database
wp db export backup.sql --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Search and replace (useful for URL changes)
wp search-replace 'old-url.com' 'new-url.com' --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Optimize database
wp db optimize --path="/Users/dwindown/Local Sites/woonoow/app/public"

6. WooCommerce Specific

# Update WooCommerce database
wp wc update --path="/Users/dwindown/Local Sites/woonoow/app/public"

# List WooCommerce orders
wp wc shop_order list --path="/Users/dwindown/Local Sites/woonoow/app/public"

# Clear WooCommerce cache
wp wc tool run clear_transients --path="/Users/dwindown/Local Sites/woonoow/app/public"

🛠️ Helper Script

A helper script has been created: wp-cli-helper.sh

Usage:

# Make it executable (already done)
chmod +x wp-cli-helper.sh

# Use it
./wp-cli-helper.sh option delete wnw_nav_tree
./wp-cli-helper.sh plugin list
./wp-cli-helper.sh cache flush

Add to your shell profile for global access:

# Add to ~/.zshrc or ~/.bash_profile
alias wplocal='wp --path="/Users/dwindown/Local Sites/woonoow/app/public"'

# Then use anywhere:
wplocal option delete wnw_nav_tree
wplocal plugin list

🔧 Troubleshooting

Database Connection Error

If you see: Error establishing a database connection

Solution 1: Start Local WP Site Make sure your Local WP site is running:

  1. Open Local WP app
  2. Start the "woonoow" site
  3. Wait for MySQL to start
  4. Try WP-CLI command again

Solution 2: Use wp-config.php Path WP-CLI reads database credentials from wp-config.php. Ensure Local WP site is running so the database is accessible.

Solution 3: Check MySQL Socket Local WP uses a custom MySQL socket. The site must be running for WP-CLI to connect.


📚 Useful WP-CLI Commands for Development

Plugin Development

# Check for PHP errors
wplocal eval 'error_reporting(E_ALL); ini_set("display_errors", 1);'

# List all options (filter by prefix)
wplocal option list --search="wnw_*"

# Get specific option
wplocal option get wnw_nav_tree

# Update option
wplocal option update wnw_nav_tree '{"version":"1.0.0"}'

# Delete option
wplocal option delete wnw_nav_tree

User Management

# List users
wplocal user list

# Create admin user
wplocal user create testadmin test@example.com --role=administrator --user_pass=password123

# Update user role
wplocal user set-role 1 administrator

Post/Page Management

# List posts
wplocal post list

# Create test post
wplocal post create --post_type=post --post_title="Test Post" --post_status=publish

# Delete all posts
wplocal post delete $(wplocal post list --post_type=post --format=ids)

Theme/Plugin Info

# List themes
wplocal theme list

# Get site info
wplocal core version
wplocal core check-update

# Get PHP info
wplocal cli info

🎯 WooNooW Specific Commands

Navigation Cache Management

# Delete navigation cache (forces rebuild on next page load)
wplocal option delete wnw_nav_tree

# View current navigation tree
wplocal option get wnw_nav_tree --format=json | jq .

# Check navigation version
wplocal option get wnw_nav_tree --format=json | jq .version

Plugin Options

# List all WooNooW options
wplocal option list --search="wnw_*" --format=table

# List all WooNooW options (alternative)
wplocal option list --search="woonoow_*" --format=table

# Export all WooNooW settings
wplocal option list --search="wnw_*" --format=json > woonoow-settings-backup.json

Development Workflow

# 1. Make code changes
# 2. Flush caches
wplocal cache flush
wplocal option delete wnw_nav_tree

# 3. Rebuild assets (from plugin directory)
cd /Users/dwindown/Local\ Sites/woonoow/app/public/wp-content/plugins/woonoow/admin-spa
npm run build

# 4. Test in browser
# 5. Check for errors
wplocal plugin status woonoow

📖 Learn More

Official Documentation

Quick Reference

# Get help for any command
wp help [command]
wp help option
wp help plugin

# List all available commands
wp cli cmd-dump

# Check WP-CLI version
wp --version

# Update WP-CLI
brew upgrade wp-cli

💡 Pro Tips

1. Use Aliases

Add to ~/.zshrc:

alias wplocal='wp --path="/Users/dwindown/Local Sites/woonoow/app/public"'
alias wpflush='wplocal cache flush && wplocal option delete wnw_nav_tree'
alias wpplugins='wplocal plugin list'

2. JSON Output

Most commands support --format=json for parsing:

wplocal option get wnw_nav_tree --format=json | jq .
wplocal plugin list --format=json | jq '.[] | select(.name=="woonoow")'

3. Batch Operations

# Deactivate all plugins except WooCommerce and WooNooW
wplocal plugin list --status=active --field=name | grep -v -E '(woocommerce|woonoow)' | xargs wplocal plugin deactivate

4. Script Integration

#!/bin/bash
# Deploy script example
echo "Deploying WooNooW..."
wplocal plugin deactivate woonoow
cd admin-spa && npm run build
wplocal plugin activate woonoow
wplocal cache flush
wplocal option delete wnw_nav_tree
echo "Deployment complete!"

Installation Summary

Installed via Homebrew:

  • WP-CLI 2.12.0
  • PHP 8.4.14 (dependency)
  • All required dependencies

Helper Files Created:

  • wp-cli-helper.sh - Quick command wrapper
  • WP_CLI_GUIDE.md - This guide

Next Steps:

  1. Ensure Local WP site is running
  2. Test: ./wp-cli-helper.sh option delete wnw_nav_tree
  3. Reload wp-admin to see settings submenu
  4. Add shell aliases for convenience

Last Updated: November 5, 2025
WP-CLI Version: 2.12.0
Status: Ready to Use