1

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.

2

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) {
            wp_delete_user($user_id[0]);
        }
    }
}

add_action('my_dailyClearOut', 'my_clearOldUsers');
  • thank you for your reply, so i have to include this in functions.php right. – krish Aug 28 '14 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 – WisdmLabs Aug 28 '14 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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