You are here

function plus1_user in Plus 1 6.2

Implements hook_user(). Delete votes for deleted users.

File

./plus1.module, line 669
A simple +1 voting widget module.

Code

function plus1_user($op, &$edit, &$account, $category = NULL) {
  if ($op == 'delete' && variable_get('plus1_delete_users', 1)) {
    $criteria = array(
      'uid' => $account->uid,
    );
    $votes = votingapi_select_votes($criteria);
    if ($votes) {
      votingapi_delete_votes($votes);

      // Now call for the results to be recalculated.
      foreach ($votes as $vote) {

        // Leave last param as FALSE to let the recalc be done by cron,
        // if we are using that method.
        votingapi_recalculate_results($vote['content_type'], $vote['content_id'], FALSE);
      }
      $c = count($votes);
      drupal_set_message(t('!count votes cleared.', array(
        '!count' => $c,
      )));
      watchdog('plus1', '!count votes deleted for user !uid (@name).', array(
        '!count' => $c,
        '!uid' => $account->uid,
        '@name' => $account->name,
      ));
    }
  }
}