You are here

function regcode_use_helper in Registration codes 6.2

Validate the use of a code, or use the code and attribute it to a user and call the hooks.

This is a helper function which wraps around the API call (regcode_use) to automate the following:

  • Call the regcode_used hooks
  • Notify the rules module
  • Update the $edit variable for hook_user

-

3 calls to regcode_use_helper()
regcode_user in ./regcode.module
Implementation of hook_user().
regcode_voucher_submit in regcode_voucher/regcode_voucher.module
Submit handler
regcode_voucher_user in regcode_voucher/regcode_voucher.module
Implementation of hook_user().

File

./regcode.module, line 359

Code

function regcode_use_helper(&$edit, &$account) {

  // If there's no code provided we have nothing to do
  if (empty($edit['regcode_code'])) {
    return;
  }

  // Use the code
  $code = regcode_use($edit['regcode_code'], $account->uid);
  watchdog('regcode', 'The registration code %code was used by !user', array(
    '%code' => $edit['regcode_code'],
    '!user' => l($account->name, 'user/' . $account->uid),
  ));

  // Trigger the regcode_used hook
  foreach (module_implements('regcode_used') as $module) {
    $hook = $module . '_regcode_used';
    $hook($edit, $account, $code);
  }

  // Notify rules module
  if (is_object($code) && module_exists('rules')) {
    rules_invoke_event('regcode_used', $account, $code);
  }

  // Update the edit variable (nothing to save here)
  $edit['regcode_code'] = NULL;
  return $code;
}