Skip to content

Instantly share code, notes, and snippets.

@iamntz
Last active May 17, 2022 16:15
Show Gist options
  • Save iamntz/0018e0535d15e00cf012a18486f102ad to your computer and use it in GitHub Desktop.
Save iamntz/0018e0535d15e00cf012a18486f102ad to your computer and use it in GitHub Desktop.
WP CLI wrapper to run commands on all sites in a network

After you install wp-cli:

If you're on Linux:

  1. Install wpmu wrapper: curl https://gist.githubusercontent.com/iamntz/0018e0535d15e00cf012a18486f102ad/raw/wpms.sh -o /usr/local/bin/wpmu
  2. make it executable: chmod +x /usr/local/bin/wpms
  3. Run commands as you'd normally do, using wpms instead, e.g. wpms plugin list

If you're on Windows:

  1. Download the powershell script in a global PATH: curl https://gist.githubusercontent.com/iamntz/0018e0535d15e00cf012a18486f102ad/raw/wpms.ps1 -O
  2. Run commands as you'd normally do: wpms plugin list
$allArgs = $PsBoundParameters.Values + $args
wp site list --field=url | ForEach-Object {
echo "running wp $allArgs --url=$_"
Invoke-Expression "wp $allArgs --url=$_"
}
#!/bin/bash
for URL in $(wp site list --field=url); do
echo "running: wp $@ --url=$URL"
wp "$@" --url="$URL"
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment