I’ve set up WP Multisite and wrote a function to daily delete all the blogs apart from one. Now when you use the wpmu_delete_blog() function the blogs are removed however their users remain, and are not associated to any site. I want to get all those users and remove them straight after deleting the blogs. All the users I create are given the role ‘demouser’. How can I do this?
1 comment
Comments are closed.
You’ll need to select all available users (see
$users
below) to loop through each one and decide if it’s a demouser; to delete all users with no associated site (seeempty($user_blogs)
below) you can callwpmu_delete_user()
(this will require to loadms.php
, if you’re loading it within a theme or plugin).Just add the following snippet right after the part in your code where you’re deleting the blogs:
Please take care of this as it will delete the unassigned users and you’ll not be able to restore deleted users!