Skip to content

Instantly share code, notes, and snippets.

@colegeissinger
Created November 2, 2022 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colegeissinger/6dfc0b721d37fe04aad0dc1f37a33223 to your computer and use it in GitHub Desktop.
Save colegeissinger/6dfc0b721d37fe04aad0dc1f37a33223 to your computer and use it in GitHub Desktop.
Copy WordPress users from one site to another in a multisite installation with WP-CLI
# Ensure you change the yoursite.com to the domain you want to use. When assigning user roles, we set a default of 'subscriber' if no user role is set on a user we want to migrate.
# This command assumes we are copying users from the "root site" of WordPress to a subsite. If you want to copy from a sub-site to another sub-site, update the first domain url to match that.
for I in $(wp user list --url=https://yoursite.com/ --fields=user_login,roles --format=csv | grep -v user_login); do WPUSER=$(echo -n $I | cut -d ',' -f 1); WPROLE=$(echo -n $I | cut -d ',' -f 2); wp user update ${WPUSER} --role=${WPROLE:-subscriber} --url=https://my-site.com/new-sub-site/; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment