Created
November 2, 2022 16:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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