On my WordPress site I require registration with email confirmation to help filter out spam users. How do I delete users that haven't activated their accounts by email automatically?

Is it possible to automatically delete users that are X days old? For example: if the user is 7 days old and not active, then the account should be automatically deleted. I'd like to check for this every day. Could someone please explain how to do this?

I am using the field name tecla_users in my database.

1 Answer 1


You can include this code by creating a new custom plugin which help you to stop this when you deactivate the plugin.

wp_schedule_event(time(), 'daily', 'my_dailyClearOut');

function my_clearOldUsers() {
    global $wpdb;

    $query = $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE datediff(now(), user_registered) > 7");

    if ($oldUsers = $wpdb->get_results($query, ARRAY_N)) {
        foreach ($oldUsers as $user_id) {

add_action('my_dailyClearOut', 'my_clearOldUsers');
  • thank you for your reply, so i have to include this in functions.php right.
    – krish
    Commented Aug 28, 2014 at 9:52
  • 1
    Yes. But i would refer you to create a new plugin and add this code in that. That will give you more control than adding it in functions.php
    – Domain
    Commented Aug 28, 2014 at 12:09
  • How will a plugin give us "more control"?
    – Pete
    Commented Dec 13, 2021 at 10:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.