Hi.
To disable the user, you can use the source code below:
// Hook into WordPress on initialization
add_action('init', 'auto_disable_candidates');
function auto_disable_candidates() {
// Check if the user is logged in
if (is_user_logged_in()) {
return;
}
// Get all users with the candidate role
$candidates = get_users(array(
'role' => 'candidate',
'fields' => 'ID',
));
foreach ($candidates as $candidate_id) {
// Check the last login time
$last_login_time = get_user_meta($candidate_id, 'last_login_time', true);
if ($last_login_time && strtotime('-2 months') > $last_login_time) {
// Disable the user account by removing the 'candidate' role
wp_update_user(array('ID' => $candidate_id, 'role' => ''));
}
}
}
// Hook into WordPress on login to update last login time
add_action('wp_login', 'update_last_login_time');
function update_last_login_time($user_login) {
$user = get_user_by('login', $user_login);
update_user_meta($user->ID, 'last_login_time', time());
}
Add the code to functions.php file.
Please recheck it.
Regards.