So Many Sites – Cleaning Up Users
There are lots of ways users can end up associated with many sites in a WordPress multisite install. That’s no big deal if it’s only five or ten but sometimes it’s way more. It’s not just messy, it actually degrades performance when you’re logged in because the admin menu bar loads all those sites. This can really become a drag as you pass a hundred or so sites. Previously, I’ve just given up on the user and made a new one. I’ve also gone through https://theSite.us/wp-admin/network/users.php and opened up a number of sites and removed the user from each one manually. That’s a pretty awful pattern but being in a hurry leads to all sorts of bad choices.1
Today I got the request to remove around six hundred sites from a particular faculty member. The request coincided with time and mental bandwidth so I opted to do this in an intelligent way. There was also no way I was going to do this by hand.
First step would be to get the user’s id from the wp_users table. You can look up users here by user_login or user_email and get to what you need pretty quickly. If you’re using Sequel Pro rather than the terminal don’t forget to restrain your searches by the right field. For this example, we’ll pretend our user_id is 666.
Now that you have your user ID, you’ll move to the wp_usermeta table. Perform your search for 666 across the user_id field. You should now have just the data associated with that user. Scanning the data should show you a number of entries under the meta_key field that say things like wp_16937_user_level and wp_16937_capabilities. In my case, I found it easiest to select all of these and delete them then re-add the user to the single blog they still wanted. Alternately, you might retain the info related to their primary_blog ID which is listed in this table as well.
If we started seeing this more frequently, I’d build out a PHP-based interaction with this where we could find a user and then manipulate things from there.
1 Proper water bailing form is rarely considered when the boat is barely being kept afloat.