How To: Mass Delete Spammy Subscribers in WordPress

Know how you can mass delete spammy subscribers in wordpress in just 5 seconds. Instead of manually deleting subscribers, you can now make use of this code and get rid of them once and for all.

Many of you might not know this, that in all the WordPress blogs, registrations are enabled by default i.e. anyone can register on your blog. And all the WordPress sites share the same url format for registration i.e. http://www.yourblogname.com/wp-login.php?action=register. So if a spammer, knows this url he can immediately subscribe to your blog.

Screen+Shot+2012 06 17+at+7.34.29+PM How To: Mass Delete Spammy Subscribers in Wordpress

Screenshot showing registrations are enabled by default

Although subscriber role is not so dangerous, having many of them will simply overload your database and will directly affect your site load time. If you never paid any attention to the users being registered on your site, then you might want to go check out the Users tab in your Sidebar.

Here you will notice pretty huge number of subscribers, if you go ahead and click the Subscribers section, you will find people have used strange names and email addresses to register on your site. So how to delete all those spammy subscribers at once? Surely you are not going to go and delete them one by one. Also if you are on a shared hosting, the Bulk actions to delete won’t work either, such as using Select all and clicking Delete won’t remove any users because your server will get overloaded and return an error that the request timed out.

After searching a lot on Google i found a post by Shane Strong (link below), which gives a great tutorial on how to delete bulk delete spam subscribers. It involved inserting code into the functions.php but i was a little scared because i knew i should never mess around with this file. So i went ahead and took a backup copy of my functions.php and inserted the code.

In just 5 seconds, the subscriber section had completely vanished. So here is how i did it.

Step 1: Take a backup copy of your functions.php file.

Step 2: Now navigate to Appearance > Editor and then click on your Theme Functions file. Here, copy the code given below and paste it just after the php line:

[php]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( wp_delete_user( $subscriber->ID ) ) {
$i++;
}
}
echo $i.’ Subscribers deleted';
} else {
echo ‘No Subscribers deleted';
}
}
remove_subscribers();[/php]
Step 3: Finally click on the Update file button. It may take sometime to update it. After it has finished updating, open a new tab in your browser and visit your site’s homepage, i.e. http://www.yourblogname.com/ and after a few seconds close this tab. Now click on the Users tab in your sidebar.

Voila! All the subscribers are gone, its like they never even existed.

If this tutorial about how to mass delete spammy subscribers in wordpress helped you, do let us know by a comment. For further updates on WordPress, subscribe to our feed.

Reference: shanestrong.com

Subscribe to our Weekly Newsletter

I take your privacy very seriously

Comments

  1. M.M. Enterprises Reply

    It is very useful & helpful post for delete Spam subscribers in WordPress. I like your post.

  2. cd Reply

    unfortunately this action caused this error: Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’

    etc. and site was rendered unviewable and could not even reinstate original code!!!???

    • Gautam Doddamani Reply

      hi that type of error typically indicates a wrong command…there must have been some simple syntax error..make sure you are copying the code as is without making any changes!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail.