Several days ago, nearly 5,000 ad subscriber users spammed my WordPress website, even causing the SQL database crash down for a while.
Spam user registrations can become a major headache, especially when your WordPress website is flooded with thousands of fake subscribers overnight. While WordPress allows user deletion through the admin dashboard, it can be cumbersome to handle bulk deletions manually, because you can only delete 20 spam users once. It will take nearly 250 times to delete all spam subscriber users completely.
In this article, we will introduce how to delete all spam subscriber users quickly and efficiently by creating a bulk delete spam users plugin for your WordPress website.
Why Use a Custom Plugin for Bulk Deletion?
A custom plugin gives you complete control over the deletion process. You can filter users by role (e.g., Subscriber) and optionally by registration date. This ensures that legitimate users are not accidentally deleted while removing spam accounts in bulk.
Step-by-Step Guide to Create the Plugin
Step 1. Create the plugin folder and write the plugin PHP file.
- Create a folder named it bulk-delete-spam-users
- In the bulk-delete-spam-users folder, create a PHP file named bulk-delete-spam-users.php
- Copy the code below to bulk-delete-spam-users.php
users} u
INNER JOIN {$wpdb->usermeta} um ON u.ID = um.user_id
WHERE um.meta_key = 'wp_capabilities'
AND um.meta_value LIKE %s ";
$params = ["%$role%"];
if (!empty($date)) {
$query .= " AND u.user_registered >= %s";
$params[] = $date;
}
$user_ids = $wpdb->get_col($wpdb->prepare($query, $params));
if (!empty($user_ids)) {
foreach ($user_ids as $user_id) {
wp_delete_user($user_id);
}
echo '' . count($user_ids) . ' users deleted successfully!
';
} else {
echo 'No users found matching the criteria.
';
}
}
?>
Bulk Delete Spam Users
Step 2: Save the Code and compress it to.zip file
Compress the folder
bulk-delete-spam-users
into a.zip
archive if you plan to upload it via the WordPress admin panel.
Step 3: Install and Activate the Plugin
Log in to your WordPress admin dashboard.
Go to Plugins > Add New and click Upload Plugin.
Upload the
bulk-delete-spam-users.php
file or its.zip
version.Activate the plugin.
Step 4: Use the Plugin to Delete Users
Navigate to Users > Bulk Delete Users in the WordPress admin panel.
Select the User Role (e.g., Subscriber).
Optionally, specify a Registered After date to delete only users registered after a specific time.
Click Delete Users.
The plugin will process the deletion and display a success message showing how many users were deleted.
The advantages of this bulk delete spam users plugin
Time-Saving: Deletes thousands of spam users in just a few clicks.
Customizable: Filters users by role and registration date, preventing accidental deletion of legitimate users.
No Third-Party Dependencies: Avoids the need for external plugins or services.
Conclusion
Bulk delete spam user plugin can help you delete flooded spam users quickly and efficiently. However, preventing spam users is the best way to secure your WordPress website. If your website does not disable user registration, we recommend 2 strategies for your website.
Enable CAPTCHA: Add CAPTCHA to your registration forms using plugins like Simple Cloudflare Turnstile.
Email Verification: Require users to verify their email before completing registration.
By this way, you can keep your WordPress user list clean and manageable.
Bulk Delete Spam Users
Bulk Delete Spam Users Plugin
Save time when deleting flooded spam users on the WordPress Website. Quickly and efficiently bulk deletes spam ad users. Delete different groups of spam users by filtering their user roles, preventing accidental deletion of legitimate users.