wp-wpcli-and-ops
WP-CLI and Ops
When to use
Use this skill for WordPress operational work:
wp search-replace(URL changes, domain migrations)- DB export/import, resets, inspections (
wp db *) - Plugin/theme install/activate/update
- Cron event listing/running
- Cache/rewrite flushing
- Multisite operations (
wp site *,--url,--network) - Building repeatable scripts (
wp-cli.yml, shell scripts)
Inputs required
- Environment (dev/staging/prod) and safety constraints
- Site root path:
--path=<wordpress-root> - Multisite:
--url=<site-url>if applicable - Any restrictions (no writes, no plugin installs, maintenance window)
Procedure
0) Safety guardrails
WP-CLI commands can be destructive. Before any write operation:
- Confirm environment (dev/staging/prod)
- Confirm targeting (path/url)
- Make a backup for risky operations
1) Safe URL/domain migration
Step-by-step:
# 1. Backup database first
wp db export backup-$(date +%Y%m%d).sql --path=/path/to/wp
# 2. Dry run to review impact
wp search-replace 'old-domain.com' 'new-domain.com' --dry-run --path=/path/to/wp
# 3. Execute the replacement
wp search-replace 'old-domain.com' 'new-domain.com' --path=/path/to/wp
# 4. Flush caches and rewrites
wp cache flush --path=/path/to/wp
wp rewrite flush --path=/path/to/wp
Common flags:
| Flag | Purpose |
|---|---|
--dry-run |
Preview changes without applying |
--precise |
Exact match only |
--recurse-objects |
Handle serialized data in objects |
--all-tables |
Include non-WP tables |
--skip-columns=guid |
Skip GUID column (recommended) |
2) Database operations
# Export
wp db export backup.sql
# Import
wp db import backup.sql
# Query
wp db query "SELECT ID, post_title FROM wp_posts LIMIT 5"
# Optimize
wp db optimize
# Reset (DESTRUCTIVE)
wp db reset --yes
3) Plugin/theme management
# List plugins
wp plugin list
# Install and activate
wp plugin install query-monitor --activate
# Deactivate
wp plugin deactivate plugin-name
# Update all
wp plugin update --all
# Same for themes
wp theme list
wp theme install theme-name --activate
4) Cron management
# List scheduled events
wp cron event list
# Run a specific event
wp cron event run my_event_hook
# Test cron is working
wp cron test
5) Cache operations
# Flush object cache
wp cache flush
# Flush transients
wp transient delete --all
# Flush rewrite rules
wp rewrite flush
6) Multisite operations
# List all sites
wp site list
# Run command on specific site
wp option get blogname --url=https://subsite.example.com
# Run command on all sites
wp site list --field=url | xargs -I {} wp option get blogname --url={}
# Network-wide plugin activation
wp plugin activate plugin-name --network
7) Automation with wp-cli.yml
Create wp-cli.yml in site root:
path: /path/to/wordpress
url: https://example.com
user: admin
# Environment-specific
@staging:
url: https://staging.example.com
@production:
url: https://example.com
ssh: user@server/path/to/wordpress
Usage:
wp @staging plugin list
wp @production cache flush
Verification
- Confirm intended side effects occurred
- Check URLs are correct after search-replace
- Verify plugins/themes in expected state
- Run health check if available:
wp doctor check
Failure modes / debugging
"Error: This does not seem to be a WordPress installation"
- Wrong
--path - Missing
wp-config.php
Multisite commands affecting wrong site
- Missing or wrong
--url
Search-replace causing serialization issues
- Use
--preciseflag - Don't replace with different length strings in serialized data without
--recurse-objects
Escalation
- If you cannot confirm environment safety, do not run write operations
- For production changes, always backup first
- Document all commands run for audit trail
More from vapvarun/claude-backup
php
Modern PHP development best practices including PHP 8.x features, OOP patterns, error handling, security, testing, and performance optimization. Use when writing PHP code, reviewing PHP projects, debugging PHP issues, or implementing PHP features outside of WordPress/Laravel specific contexts.
45seo-optimization
Optimize websites for search engines including on-page SEO, technical SEO, meta tags, schema markup, Core Web Vitals, and keyword optimization. Use when improving search rankings, auditing SEO, or optimizing content for Google.
11frontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.
11typescript
TypeScript development best practices including type system, generics, utility types, configuration, and patterns for React, Node.js, and full-stack applications. Use when writing TypeScript code, converting JavaScript to TypeScript, debugging type errors, or implementing type-safe patterns.
9wp-security-review
WordPress security audit and vulnerability analysis. Use when reviewing WordPress code for security issues, auditing themes/plugins for vulnerabilities, checking authentication/authorization, analyzing input validation, or detecting security anti-patterns, or when user mentions "security review", "security audit", "vulnerability", "XSS", "SQL injection", "CSRF", "nonce", "sanitize", "escape", "validate", "authentication", "authorization", "permissions", "capabilities", "hacked", or "malware".
8security
Web application security best practices including OWASP Top 10, authentication, authorization, input validation, cryptography, and secure coding patterns. Use when implementing security features, reviewing code for vulnerabilities, hardening applications, or fixing security issues.
8