I have added this to the users as they log into any of the sites on my multisite.
update_user_meta( $user_id, '_last_login', time() );
Now I want to delete all of the users that have not logged in for the past 6 months. I am looking for the sql version of this as I will then include it into a scheduled task to run once a week to clean the database.
$time = strtotime('-1 hour');
$user_query = new WP_User_Query(array('meta_key' => '_last_login', 'meta_value' => $time, 'meta_compare' => '<=', 'fields' => 'ID'));
if (!function_exists('wpmu_delete_user')) {
include(ABSPATH . "wp-admin/includes/ms.php");
}
if ($user_query->results) {
foreach ($user_query->results as $old_user) {
wpmu_delete_user($old_user);
}
};
wp_delete_user
?WP_User_Query
andwp_delete_user
, plus awp_cron
job should do it.