You are here

simple_ldap_user_delete_blocked.module in Simple LDAP 7.2

simple_ldap_user_delete_blocked module file.

File

contrib/simple_ldap_user_delete_blocked/simple_ldap_user_delete_blocked.module
View source
<?php

/**
 * @file
 * simple_ldap_user_delete_blocked module file.
 */

/**
 * Implements hook_user_update().
 *
 * Deletes a user from LDAP if status is changed to "blocked".
 */
function simple_ldap_user_delete_blocked_user_update(&$edit, $account, $category) {

  // Don't do anything for uid 1.
  if ($account->uid == 1) {
    return;
  }

  // Don't do anything if the hook was called via hook_sync_user_to_drupal().
  if (empty($account->hook_sync_user_to_drupal)) {
    if (!$edit['status']) {

      // Delete the user from LDAP if changed to "blocked".
      $ldap_user = SimpleLdapUser::singleton($account->name);
      $ldap_user
        ->delete();
    }
  }
}