Support » Networking WordPress » Scripting MU blog deletion

  • I’m working on the automation of account deletion for my school. Basically, I’m scripting the deletion of a user’s system account, ldap info, Google account, etc. The goal is to have a (linux) command-line script that can be used to remove a user from the system.

    When it comes to removing the user and blog from WordPress (3.0.1 w/multisite), I’m a little confused. Should I be trying to call wpmu_delete_blog() and confirm_delete_users() directly, or will that fail because I can’t authenticate from a script, and I have the wrong referrer? Is anyone else doing this in a sane (and secure) way? I’d prefer to not to depend too much on deep core functions, but I also don’t think it would be wise to just edit the database directly, either.

    Any suggestions on approaches to this would be appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Automatically calling confirm_delete_users() should reasonably(safely/correctly) delete users. Automatically deleting blogs worries me, though.

    wpmu_delete_blog(from wp-admin/includes/ms.php) needs a $blog_id to delete. The trick there will be to make sure you get hold of the right $blog_id to automatically delete. Users can belong to several blogs, they can make any blog they belong to as their primary blog – even the main, they can remove themselves from a blog altogether.

    Also, even though $blog_id and $user_id may be the same during a setup(ie. user 63 also has blog 63), eventually $blog_id differs from $user_id sometime down the road when blogs or users outnumber each other(ie. user 1234 has blog 1543)

    Yep. I would definitely not rely on the $blog_id and $user_id being the same. In most cases on my server, they’re not.

    Would it be a better idea to just delete the user, and then use a separate cleanup script to delete all of the blogs that don’t have owners? I’m not entirely sure I like that, either. And, admittedly, I haven’t really looked at what happens to the blog when you delete its owner, so it may not even be feasible (if, for example, it reverts to the admin account).

    In my case, the users log in, and I use wpdirauth to authenticate them against ldap. If they don’t have a blog, it creates one of the form http://mydomain/username. So when deleting, I could be able to just look up that user’s blog by the address, and get the correct id to remove. I don’t have any cases where they have multiple blogs, so it should be pretty straightforward.

    Thanks for your help. I think I’m on the right track. I was mostly worried about it not working because I was calling it from outside the WP admin interface.

    Just to follow up on this, I was in dependency hell when I was trying to call wpmu_delete_blog from a non-wordpress script. I ended up just setting the deleted flag in the wp_blogs table. That should prohibit access to the blog’s content, which was the main point anyway.

    For users, I just looked up the id from wp_users based on username, and then deleted that userid from the wp_users and wp_usermeta tables.

    So far, everything seems to be working all right.

    Thanks again for your help.

    I support your flagging for manual deletion. There is certainly something more comforting by having a human being giving the blog to be deleted the once over before it is too late to resurrect.

    @jschinker, I am trying to do the same thing (from a plugin) but I am also in dependency hell. Is there a special way to load the WPMU api?

    Andrea Rennick


    Customer Care at Copyblogger Media and Studiopress

    Are you still using WPMU? what version?

    If it’s more than 3,0, then it’s multisite – not wpmu.

    I’m on 3.1.2 wordpress multisite, sorry Andrea_r.

    Here is an example of what I have,

    Plugin information, etc etc
    wpmu_delete_blog('6', true);

    And here is what I get,

    Fatal error: Call to undefined function wpmu_delete_user() in /filepath/main.php on line 12

    I tried including ms.php but no matter what I include there is always another dependency.. there is probably a certain way to load the multisite api and functions?


    Also, just thought I’d add. I have this code setup on a separate php file,

    // Load WordPress framework and WPMU api
    wpmu_delete_blog('6', true);

    And when I run that file in the browser it successfully deletes users/blogs.

    Sorry for the late reply here. I actually cheated. In my case, all of my blogs are, so it was as simple as:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    This is not done anywhere in WordPress itself. This is part of a much larger script that deletes the user system-wide.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Scripting MU blog deletion’ is closed to new replies.