I use the following SQL code for cleaning up bots:
-- Bot clean-up script
create temporary table wp_users_q_tmp as (select * from wp_users
where id not in (select distinct user_id from wp_comments where user_id is not null)
and user_registered < now() - interval 3 day);
insert into wp_users_q select * from wp_users_q_tmp;
delete from wp_users where id in (select id from wp_users_q_tmp);
This works, and also allows me to restore wrongly-deleted accounts by grabbing them from the wp_users_q table. (q == quarantine)
One side-effect however I notice with WordPress 3.9.1 is the user counts are wrong afterwards.
My user listing page shows:
All (16,581) |
Administrator (1) |
Subscriber (16,580)
yet, according to SQL:
mysql> select count(*) from wp_users;
+----------+
| count(*) |
+----------+
| 150 |
+----------+
1 row in set (0.00 sec)
So it’s keeping count somewhere else and I haven’t figured out how to update that count.