WP-CLI
WP-CLI is the official command-line interface for managing WordPress installations. It lets you perform almost any WordPress admin task from the terminal: install and update plugins and themes, manage users, run database operations, generate content, and debug issues, all without logging into the WordPress admin dashboard.
§ 1 Definition
WP-CLI is a command-line tool that provides a Unix-like interface for managing WordPress installations. First released in 2011 and now maintained by the WordPress project itself, WP-CLI is the most efficient way to manage WordPress sites at scale. With WP-CLI, you can execute WordPress operations from the terminal that would otherwise require clicking through the admin dashboard. Installing a plugin: `wp plugin install woocommerce --activate`. Clearing the cache: `wp cache flush`. Generating test content: `wp post generate --count=100 --post_type=page`. Managing users: `wp user create jane [email protected] --role=editor`. WP-CLI is indispensable for WordPress developers, site maintainers, and anyone managing multiple WordPress installations. It enables scripting, automation, CI/CD integration, and remote management via SSH. The tool is open source, actively maintained, and has a rich ecosystem of community commands extending its functionality.
§ 2 Essential WP-CLI Commands
WP-CLI organizes commands into a tree structure. Here are the most useful commands for daily site management: Installation and Core: - `wp core download` Download WordPress core files - `wp core config` Generate wp-config.php - `wp core install` Run the famous 5-minute installation - `wp core update` Update WordPress to the latest version - `wp core check-update` Check if an update is available Plugins and Themes: - `wp plugin list --status=active` List active plugins - `wp plugin install {slug} --activate` Install and activate a plugin - `wp plugin update --all` Update all plugins - `wp theme activate {slug}` Switch theme - `wp theme delete {slug}` Delete a theme Content Management: - `wp post list --format=table` List recent posts - `wp post create --post_title="Hello" --post_content="World" --post_status=publish` Create a post - `wp post delete $(wp post list --format=ids)` Delete all posts - `wp post generate --count=50` Generate sample posts Database Operations: - `wp db optimize` Optimize the database - `wp db export` Export the database to a SQL file - `wp db import {file}.sql` Import a database - `wp db search 'old.com' 'new.com' --dry-run` Search/replace across the database User Management: - `wp user list` List all users - `wp user create {username} {email} --role={role}` Create a new user - `wp user meta update {user} wp_user_level 10` Update user capabilities - `wp user reset-password $(wp user list --format=ids)` Reset all passwords Maintenance and Debugging: - `wp maintenance-mode activate` Enable maintenance mode - `wp cache flush` Clear object cache - `wp rewrite flush` Regenerate permalinks - `wp config set WP_DEBUG true --raw` Enable debug mode - `wp transient delete --all` Clear all transients
§ 3 WP-CLI for Automation and DevOps
WP-CLI's real power emerges when you script it. Common automation patterns: Automated deployments: ```bash # Pull latest code, update plugins, clear cache git pull origin main wp plugin update --all wp cache flush wp rewrite flush ``` Staging site creation: ```bash # Clone a production site to staging wp db export production-backup.sql wp db import production-backup.sql wp search-replace 'example.com' 'staging.example.com' wp user update admin --user_pass=staging-password ``` Scheduled maintenance: ```bash # Cron job: daily database optimization wp db optimize wp transient delete --all wp post delete $(wp post list --post_type='revision' --format=ids) --force ``` Bulk operations on multi-site networks: ```bash # Update plugins on all sites in a network wp site list --field=url | while read site; do wp plugin update --all --url=$site done ``` WP-CLI integrates with CI/CD pipelines (GitHub Actions, GitLab CI), monitoring tools, and hosting platforms. Most managed WordPress hosts (WP Engine, Kinsta, Pagely) include WP-CLI on their servers. For developers, WP-CLI is the difference between managing one site and managing one hundred.
§ 4 Installing WP-CLI
WP-CLI is a PHP Phar (PHARchive) file that runs on any system with PHP 5.6+. Basic installation (Linux/macOS): ```bash curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp ``` Verify installation: ```bash wp --info ``` Tab completion (optional, highly recommended): ```bash eval "$(wp --allow-root cli completions)" # Add to .bashrc or .zshrc for persistence ``` WP-CLI can also be installed via: - Homebrew: `brew install wp-cli` - Docker: Available in official WordPress Docker images - Composer: `composer require wp-cli/wp-cli-bundle` Once installed, run `wp help` to explore available commands. The `wp help {command}` syntax provides detailed documentation for any command.
§ 5 Note
§ 6 In code
# Example: bulk update workflow with WP-CLI
# Check available updates first
wp plugin list --update=available --format=count
# Dry-run the updates
wp plugin update --all --dry-run
# Apply updates + clear cache
wp plugin update --all
wp theme update --all
wp core update
wp cache flush
wp rewrite flush
# Verify site is still up
wp post list --posts_per_page=1§ 7 Common questions
- Q. Is WP-CLI safe to use on production sites?
- A. Yes, with caution. Always use --dry-run flags for destructive operations. Test scripts on staging first. Keep a recent backup before running update commands.
- Q. Can WP-CLI damage my WordPress installation?
- A. It can if you run destructive commands without backups. `wp db drop` will delete your database. `wp site delete` will remove a multisite subsite. Use responsibly.
- Q. Does WP-CLI work with all WordPress hosts?
- A. Most managed WordPress hosts include WP-CLI. Some shared hosting providers restrict it. Check with your host or install WP-CLI in a custom user directory.
- WP-CLI is the official command-line tool for managing WordPress, enabling admin tasks from the terminal.
- It's essential for automating updates, deployments, database operations, and bulk content management.
- Commands follow a `wp {namespace} {action}` pattern and can be scripted into workflows.
- Install via Phar, Homebrew, or Docker. Use --dry-run on production and always maintain backups.
We use WP-CLI for everything in our maintenance workflow. Automated updates, database optimization, security checks. It's how we keep client sites running smoothly on our WordPress maintenance plan at $149/mo. Get in touch.
Get in touchWP-CLI is the official command-line interface for managing WordPress installations. It lets you perform almost any WordPress admin task from the terminal: install and update plugins and themes, manage users, run database operations, generate content, and debug issues, all without logging into the WordPress admin dashboard.
Category: Cms (also: Software Engineering, Devops)
Author: Atomic Glue Editorial Team
## Definition
WP-CLI is a command-line tool that provides a Unix-like interface for managing [WordPress](/glossary/wordpress) installations. First released in 2011 and now maintained by the WordPress project itself, WP-CLI is the most efficient way to manage WordPress sites at scale. With WP-CLI, you can execute WordPress operations from the terminal that would otherwise require clicking through the admin dashboard. Installing a plugin: `wp plugin install woocommerce --activate`. Clearing the cache: `wp cache flush`. Generating test content: `wp post generate --count=100 --post_type=page`. Managing users: `wp user create jane [email protected] --role=editor`. WP-CLI is indispensable for WordPress developers, site maintainers, and anyone managing multiple WordPress installations. It enables scripting, automation, CI/CD integration, and remote management via SSH. The tool is open source, actively maintained, and has a rich ecosystem of community commands extending its functionality.
## Essential WP-CLI Commands
WP-CLI organizes commands into a tree structure. Here are the most useful commands for daily site management: **Installation and Core:** - `wp core download` Download WordPress core files - `wp core config` Generate wp-config.php - `wp core install` Run the famous 5-minute installation - `wp core update` Update WordPress to the latest version - `wp core check-update` Check if an update is available **Plugins and Themes:** - `wp plugin list --status=active` List active plugins - `wp plugin install {slug} --activate` Install and activate a plugin - `wp plugin update --all` Update all plugins - `wp theme activate {slug}` Switch theme - `wp theme delete {slug}` Delete a theme **Content Management:** - `wp post list --format=table` List recent posts - `wp post create --post_title="Hello" --post_content="World" --post_status=publish` Create a post - `wp post delete $(wp post list --format=ids)` Delete all posts - `wp post generate --count=50` Generate sample posts **Database Operations:** - `wp db optimize` Optimize the database - `wp db export` Export the database to a SQL file - `wp db import {file}.sql` Import a database - `wp db search 'old.com' 'new.com' --dry-run` Search/replace across the database **User Management:** - `wp user list` List all users - `wp user create {username} {email} --role={role}` Create a new user - `wp user meta update {user} wp_user_level 10` Update user capabilities - `wp user reset-password $(wp user list --format=ids)` Reset all passwords **Maintenance and Debugging:** - `wp maintenance-mode activate` Enable maintenance mode - `wp cache flush` Clear object cache - `wp rewrite flush` Regenerate permalinks - `wp config set WP_DEBUG true --raw` Enable debug mode - `wp transient delete --all` Clear all transients
## WP-CLI for Automation and DevOps
WP-CLI's real power emerges when you script it. Common automation patterns: **Automated deployments:** ```bash # Pull latest code, update plugins, clear cache git pull origin main wp plugin update --all wp cache flush wp rewrite flush ``` **Staging site creation:** ```bash # Clone a production site to staging wp db export production-backup.sql wp db import production-backup.sql wp search-replace 'example.com' 'staging.example.com' wp user update admin --user_pass=staging-password ``` **Scheduled maintenance:** ```bash # Cron job: daily database optimization wp db optimize wp transient delete --all wp post delete $(wp post list --post_type='revision' --format=ids) --force ``` **Bulk operations on multi-site networks:** ```bash # Update plugins on all sites in a network wp site list --field=url | while read site; do wp plugin update --all --url=$site done ``` WP-CLI integrates with CI/CD pipelines (GitHub Actions, GitLab CI), monitoring tools, and hosting platforms. Most managed WordPress hosts (WP Engine, Kinsta, Pagely) include WP-CLI on their servers. For developers, WP-CLI is the difference between managing one site and managing one hundred.
## Installing WP-CLI
WP-CLI is a PHP Phar (PHARchive) file that runs on any system with PHP 5.6+. **Basic installation (Linux/macOS):** ```bash curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp ``` **Verify installation:** ```bash wp --info ``` **Tab completion (optional, highly recommended):** ```bash eval "$(wp --allow-root cli completions)" # Add to .bashrc or .zshrc for persistence ``` WP-CLI can also be installed via: - **Homebrew:** `brew install wp-cli` - **Docker:** Available in official WordPress Docker images - **Composer:** `composer require wp-cli/wp-cli-bundle` Once installed, run `wp help` to explore available commands. The `wp help {command}` syntax provides detailed documentation for any command.
## Note
WP-CLI works on WordPress multisite networks, but commands need the --url parameter to target specific subsites. Use `wp help` to explore multisite-specific commands.
## In code
# Example: bulk update workflow with WP-CLI # Check available updates first wp plugin list --update=available --format=count # Dry-run the updates wp plugin update --all --dry-run # Apply updates + clear cache wp plugin update --all wp theme update --all wp core update wp cache flush wp rewrite flush # Verify site is still up wp post list --posts_per_page=1
## Common questions
Q: Is WP-CLI safe to use on production sites?
A: Yes, with caution. Always use --dry-run flags for destructive operations. Test scripts on staging first. Keep a recent backup before running update commands.
Q: Can WP-CLI damage my WordPress installation?
A: It can if you run destructive commands without backups. `wp db drop` will delete your database. `wp site delete` will remove a multisite subsite. Use responsibly.
Q: Does WP-CLI work with all WordPress hosts?
A: Most managed WordPress hosts include WP-CLI. Some shared hosting providers restrict it. Check with your host or install WP-CLI in a custom user directory.
## Key takeaways
- WP-CLI is the official command-line tool for managing WordPress, enabling admin tasks from the terminal.
- It's essential for automating updates, deployments, database operations, and bulk content management.
- Commands follow a `wp {namespace} {action}` pattern and can be scripted into workflows.
- Install via Phar, Homebrew, or Docker. Use --dry-run on production and always maintain backups.
## Related entries
- [WordPress](atomicglue.co/glossary/wordpress)
- [Plugins](atomicglue.co/glossary/plugins)
- [Themes](atomicglue.co/glossary/themes)
- [CMS](atomicglue.co/glossary/cms)
Last updated July 2025. Permalink: atomicglue.co/glossary/wp-cli