Nov 23, 2020 in Drupal 8

An important clean-up task on bigger websites is to remove unused accounts. This snippet does the work. 

use  \Drupal\user\Entity\User; 

 $ids = \Drupal::entityQuery('user')
    ->execute();
  $users = User::loadMultiple($ids);
  foreach($users as $user) {
    if (!$user->getLastAccessedTime()) {
      $user->delete();
    }
  }

 

Comments