Bulk Delete WordPress Spam Users

Owning a blog can be tough to maintain. One of the biggest annoyances are all those pesky spam users that subscribe. Most of the time these are bots or a company doing a mass submission. Well there are plugins out there like WP-re-CAPTCHA, Sipmle CAPTCHA, SI CAPTCHA Anti-Spam, or others. Now even tho you have protected your self against future spam bots and spam users you still have to get rid of all the already created users. Now I don’t know about you but I have seen sites with hundreds of thousands of spam users. This is really bad for your server, your site, your protection, and more. My first website I went through deleting users I had to delete around 4000. Now I deleted these 1 page at a time and I am not sure if you have checked but you can only delete 20 at a time on the pages. So what would that be 200 times. How nice would it be to be able to do a mass delete of just the subscribers. Well there are a couple ways to get this done easily. One most people don’t know about the option to up the amount of users shown per page. Really simple to do this go to your users section and click the Screen Option. You will find an are with a section called show on screen. You can set this to what you want. Really easy but not known by many.

Doing It Through Code

The other option is to do this with code. Another really simple way delete a bunch or WordPress spam users is to put the code below into your functions.php file and then go to your site. Once you have went to your site go back to your functions file and remove the code.

That is it really simple and really quick. Now you don’t have to spend a long time deleting 20 by 20. Do everything in bulk it is easier.

A website like http://www.realityco.com will provide you with the highest quality in the industry.

In case you’re interested in knowing more info on web design london, stop by http://chris-mackie.co.uk

  • Jeremiah Claybrooks

    Hi there, looks like a great script and I think I’m close to getting it to work. I’m more of a front end guy so I had a couple questions: is there any specific spot where I place this chuck of code and should I wait a few minutes and let it run? The site I’m working on has 54k plus bot subscribers. Thank you!

  • Ed

    worked perfect for me running WP 4.1.1 – Thanks…How about the “pending” role?

    • shanestrong05

      Hey Ed
      Best bet would be to click the role then click Screen Options in upper right. Change the number by Users to a large amount then you can select and delete. You could also try changing the code role to Pending. I would recommend the Screen Options.

      • Ed

        Perfect. Who knew…lol…

  • wizle

    i tried it on my website jaradio.com and it works. takes a long time if you have alot of users

  • Love Me Architecture

    Um– I have 48K splog users on a site that not even public yet… WP crashes – it runs out of memory
    —is there a code change to delete just 1,000 users, for example?

    then I’d open the site 49x and they would be gone

    I DO NOT understand PHP

    Thanks Steve

    • shanestrong05

      Hey Steve

      The script should work even with all your spam users but if you were to want it to only do 1000 users I would change it to something like below:

      function remove_subscribers() {
      global $wpdb;
      $args = array( ‘role’ => ‘Subscriber’ );
      $subscribers = get_users( $args );
      if( !empty($subscribers) ) {
      require_once( ABSPATH.’wp-admin/includes/user.php’ );
      $i = 0;
      foreach( $subscribers as $subscriber ) {
      if($i==999) break;
      if( wp_delete_user( $subscriber->ID ) ) {
      echo $i.’ Subscribers deleted’;
      } else {
      echo ‘No Subscribers deleted’;

      What this will do is start with the first user and give them a $i variable of 0, once the $i variable gets to 999 (1000 subscribers) it will break the foreach loop. So every time you load a page or attempt to load a page it will delete 1000 subscribers. You will have to make sure that you remove the function once finished with it because if you do not it will keep deleting all the subscribers.

      • Love Me Architecture

        Thanks Shane – you should blog this up. I threw away the entire site– with 49,000 users and 7600 groups, etc etc it was just impossibly damaged
        –I am rebuilding very quickly

        Much Aloha

        • shanestrong05

          Yeah I probably should do a advanced version of this script since it is almost 2 years old and people are still using it. Hopefully the rebuild goes well. You should shoot me a link once you get the new site finished.

  • Novellus

    OK… I just pasted this code into my blog’s functions.php file.. just like in the instructons.
    Re-loaded my blog.. Ends with an error – kinda scary… then I removed the code, and BAM…
    4500+ unwanted users were gone!
    Thank You

  • Hi there,

    I have done exactly as you’ve described in this article.
    However, ever since I tried to save the script, my browser hasn’t stopped loading. I have 24k+ subscribers. Do you think that’s the issue?


  • Nice post….It worked…but can you please explain this php code to me 🙂

    • shanestrong05

      The code you just paste into your functions.php file and then go to your site. It will auto run once you go to any page. It will delete every Subscriber. Once it is done just remove it from your functions.php or comment it out.

      • Yea, I did….I replace subscriber with contributor and all these tags….after running this code it deleted “All Accounts” not just spam… 🙁

        BTW I meant can you explain this code not process 🙂 Thanks

        • shanestrong05

          The code is made to be really simple. It does not remove just the spam users it removes all of the users. I would only recommend using it if you are one of the sites that has thousands of subscribers that are all fake/spam.

          The code runs the wordpress delete user function on every user that have role Subscriber.

          • Understood…. I’m a teen & new to wp…. & trying to make my site wwefansnation.com better day by day 🙂 your article screwed my readers but still thanks :p

          • at first I was a bit fucked up…but then I realized that over 120 spam bots are gone… 🙂

  • sir i want to remove authors instead of subscribers. already deleted several thousands of spam posts using mass delete plugin but i can’t delete authors, already registered. pl help me

    • all you would have to do is display authors instead of subscribers

  • thanks a lot man you saved my day…i delete about 6k spammy subscribers on my wordpress blog. u r the best…i will soon do a tutorial on the same subject and give a linkback to your blog..happy coding 😀