List Multisite Users

Using wp-cli(1) If I run wp user list I get a list of the users (2 admins in my case) at the top level of multisite(2). enter image description here

List Multisite Sites' Users

I have 25 sites with various users. Some users are in different sites as different roles. When I use the network flag wp user list --network I get the same style report minus the roles column; but the report spans the multisite network of sites. enter image description here

List Multisite Sites' Users+Roles

My goal is to list all the admins of each site. This is where I am stuck. Apparently, adding the additional flag --role=administrator adds nothing to the conversation. It will run the same network report of all registered users.

Is there a combination of flags that will list the users along with their roles?


References:

  1. wp-cli.org
  2. codex.wordpress.org/Glossary#Multisite

Side note: Dividing these up by site would also be handy.

up vote 5 down vote accepted

List all the admins of each site

Side note: Dividing these up by site would also be handy.

Let's do that here:

We can list the url of each site with:

wp site list --field=url

We can list all administrators of a given site with:

wp user list --role=administrator --url=https://example.tld/site1

These commands can be combined with e.g. xargs as suggested on the wp-cli site:

wp site list --field=url  \
  | xargs -I % wp user list --role=administrator --url=%

We might also want to use | tail --lines=+2 to skip the url header, of the first command as explained in the tail manual and answers like this one.

Thanks to @grappler for suggesting --field="url" instead of --fields="url" with | tail --lines=+2 to skip the header row.

If we want to display the url before each table:

for url in $( wp site list --field="url" ); \
do \
   echo $url; \
   wp user list --role=administrator --url=$url; \
done; 
  • Thank you for that! I am closer now. This is what I am getting now. – nic Aug 8 '17 at 3:37
  • You're welcome. I updated with a way to display the url before each table @nic – birgire Aug 8 '17 at 5:28
  • Perfect! You couldn't have been more helpful. I think I fall in love with the terminal a little more every day. I've served this up as a script the rest of my team can use in the /usr/local/bin/ – nic Aug 8 '17 at 15:03
  • Glad to hear it helped and I agree with you, it's great to be able to work with WordPress through the command line ;-) @nic – birgire Aug 8 '17 at 15:12
  • 1
    @birgire If you just use --field=url then you don't need to use | tail --lines=+2. It is field instead of fields. Singular not plural. – grappler Aug 29 at 12:38

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.