Skip to content

Instantly share code, notes, and snippets.

@dlh01
Last active June 27, 2023 20:25
Show Gist options
  • Save dlh01/be208e667ec35118126f to your computer and use it in GitHub Desktop.
Save dlh01/be208e667ec35118126f to your computer and use it in GitHub Desktop.
WP-CLI: Add a user to all sites in a network
#!/bin/bash
# Usage: ./distribute_user.sh [username] [role]
ARGS="$@"
echo "Adding user $1 as $2 to all sites"
SITES=$(wp site list --field=url --format=csv)
for site in $SITES
do
wp user set-role $1 $2 --url=$site
done
@mustardBees
Copy link

Elegant solution, saved me from a laborious task. Thank you.

@pjrobertson
Copy link

FYI this seems to add the user to the site, but the sites won't appear in the user's drop down list on the backend. You still have to 'add' them in manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment