Auto delete WordPress users according to time since registering?

Solution:

You want to have a look at the user_registered column in the wp_users table. Since you’re using WordPress, I’ll assume that you’re also using MySQL — in which case you can use the DATEDIFF() function in your SQL to work out how many days ago they registered.

The SQL to delete everyone who is 30 days old (or older) is:

DELETE FROM `wp_users` 
WHERE datediff(now(), `user_registered`) >= 30

You can replace the DELETE FROM with SELECT * FROM in that query to see which users the delete would affect, if you want to preview who will be deleted by the query.

You could set this up as a cronjob using the language of your choice, which might be a PHP script that just runs the SQL above. You could then run that at midnight every day by putting the following into your crontab:

0 0 * * * php ~/delete_expired_users.php

If you’re new to cronjobs, then that will simply run the command php ~/delete_expired_users.php every day (that’s that the * denotes) at hour 0, minute 0 (ie. midnight). Let me know if you need any more detailed instructions.