4

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.

1 Answer 1

7

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; 
6
  • Thank you for that! I am closer now. This is what I am getting now.
    – nic
    Aug 8, 2017 at 3:37
  • You're welcome. I updated with a way to display the url before each table @nic
    – birgire
    Aug 8, 2017 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, 2017 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, 2017 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, 2018 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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