Skip to main content

WP-CLI Usage

Common Commands

# Database operations
wp db export /tmp/opshell-$(date +%Y%m%d).sql
wp db import /tmp/opshell-backup.sql
wp db query "SELECT * FROM wp_options WHERE option_name LIKE '%opshell%'"

# Plugin management
wp plugin list --status=active
wp plugin update --all
wp plugin deactivate wpcodebox2 --debug

# Post operations
wp post list --post_type=page --fields=ID,post_title,post_date
wp post update 123 --post_title="New Title"
wp post create --post_type=page --post_title="Test" --post_status=draft

# Option management
wp option get opshell_reoon_api_key
wp option update opshell_smtp_host "smtp.example.com"

# Cache
wp cache flush
wp lscache-purge all

# User management
wp user list --role=administrator
wp user create editor-user editor@example.com --role=editor

WPCodeBox2 Snippet Management

# List snippets
wp db query "SELECT id, title, enabled, hook FROM wp_wpcb_snippets"

# Get snippet code
wp db query "SELECT code FROM wp_wpcb_snippets WHERE id = 1"

# Update snippet code via file
wp eval 'file_put_contents("/tmp/code.php", $wpdb->get_var("SELECT code FROM wp_wpcb_snippets WHERE id = 1"));'
# Edit code, then:
wp eval '
$code = file_get_contents("/tmp/updated-code.php");
global $wpdb;
$wpdb->update("wp_wpcb_snippets", ["code" => $code], ["id" => 1]);
'

Aliases

# ~/.wp-cli/config.yml
@opshell:
path: /home/wp_opshell_dev/sites/opshell.dev
ssh: rezriz@GC-SG-M8

Usage: wp @opshell plugin list