Today I wanted to make sure a bunch of editors from one site existed as editors of a new staging site that we’re building out. Both sites exist as part of the same multisite network.
wp user list --role=editor --url=prod.site.edu --field=user_login | xargs -n1 -I % wp --url=stage.site.edu user set-role % editor
This tells WP-CLI to list only the
user_login field for all of the editors on
prod.site.edu. It then passes this list via pipe to
xargs, which runs another
wp command that tells WP-CLI to set the role of each user as editor on
Because users are already “created” at the global level in multisite, they are added to other sites by setting their role with
wp user set-role.
I’d estimate that with a list of 15 users, this probably saved closed to 15 minutes and didn’t require a whole bunch of clicking and typing with two browser windows open side by side.
Props to Daniel’s runcommand post for providing an easy framework.