unloc / wp-cli-all-sites
Run any WP-CLI command across all sites in a multisite network
Package info
github.com/unlocnl/wp-cli-all-sites
Type:wp-cli-package
pkg:composer/unloc/wp-cli-all-sites
Requires
- php: >=8.2
- wp-cli/wp-cli: ^2.5
Requires (Dev)
README
Run any WP-CLI command across every site in a WordPress multisite network.
No more piping wp site list through xargs. Just add --all-sites to any command and it runs on every site in the network, with progress tracking, error handling, and site exclusion built in.
Requirements
- PHP 8.2+
- WP-CLI 2.5+
- WordPress multisite installation
Installation
wp package install unloc/wp-cli-all-sites
WP-CLI versions before 2.13 cannot resolve Packagist packages due to a bug in package-command. Use the git URL instead:
wp package install https://github.com/unlocnl/wp-cli-all-sites.git
Usage
Add --all-sites to any WP-CLI command to run it on every site in the network.
wp option get blogname --all-sites
Flags
| Flag | Description |
|---|---|
--all-sites |
Run the command on every site in the network |
--continue-on-error |
Don't stop on first site failure |
--except=<list> |
Comma-separated URLs or blog IDs to skip |
Destructive commands (site delete, site empty, site archive, etc.) prompt for confirmation. Pass --yes to skip the prompt.
Sub-commands run with stdin detached, so interactive prompts in the underlying command won't work. Pass --yes or equivalent flags to bypass them.
Examples
# Get blogname for all sites
wp option get blogname --all-sites
# Run on all sites except shop
wp cache flush --all-sites --except=shop.example.com
# Exclude by blog ID
wp cache flush --all-sites --except=3,7
# Continue even if a site fails
wp plugin list --all-sites --continue-on-error
# Run cron for all sites
wp cron event run --due-now --all-sites --continue-on-error
# Destructive: requires --yes
wp site empty --all-sites --yes
License
MIT