By photocurio


2019-07-09 13:56:32 8 Comments

I am trying to loop through all sites on a multisite network, and for each site, delete all subscriber users. I have tried this WP-CLI command:

wp site list --field=url | xargs -n 1 -I ^ wp user list --url=^ --role=subscriber --field=ID | xargs -n 2 -I % ^ wp user delete % --url=^ --reassign=4

I can't find a way to pass the ^ value to the second xargs command. Anyone?

1 comments

@Tom J Nowell 2019-07-09 14:52:44

xargs is unnecessary, something similar to this will do the job without any piping or xargs:

sites=$(wp site list --field=url)
for site in $sites
do
  users=$(wp user list --url="$site" --role=subscriber)
  for user in $users
  do
    wp user delete $user --url="$site" --reassign=4
  end
end

@photocurio 2019-07-09 18:55:31

Its been a while since I wrote a bash script, but why not? This is the script that works for me (maybe you can't put in line breaks in a comment?): #!/bin/bash sites=$(wp site list --field=url) for site in $sites do users=$(wp user list --url=$site --role=subscriber --field=ID) for user in $users do wp user delete $user --url=$site --reassign=4 done done

Related Questions

Sponsored Content

0 Answered Questions

remove roles from multisite users but retain post attribution?

1 Answered Questions

[SOLVED] Possible to have duplicate usernames on different two multisites

1 Answered Questions

[SOLVED] Custom column under All Users (multisite network admin)?

0 Answered Questions

Allow users on a multisite network to only have access to one subdomain

  • 2017-06-23 20:47:06
  • blank473
  • 410 View
  • 0 Score
  • 0 Answer
  • Tags:   multisite

2 Answered Questions

[SOLVED] User Role is Not Specifying in Wordpress Multisite?

1 Answered Questions

[SOLVED] Execute wp-cli command on all sites on server

  • 2016-11-01 11:30:52
  • consc198
  • 169 View
  • 2 Score
  • 1 Answer
  • Tags:   wp-cli

0 Answered Questions

Error: reassigning content to a different user is not supported on multisite

  • 2017-03-08 13:20:56
  • yaris
  • 41 View
  • 1 Score
  • 0 Answer
  • Tags:   multisite wp-cli

1 Answered Questions

2 Answered Questions

[SOLVED] Listing of all uploaded files in network sites

Sponsored Content