You are here

function _lockr_set_key in Lockr 7

Same name and namespace in other branches
  1. 7.3 lockr.module \_lockr_set_key()
  2. 7.2 lockr.module \_lockr_set_key()

Sets a key value in lockr.

Parameters

string $key_name: The key name.

string $key_value: The key value.

string $key_label: The key label.

string|bool $old_name: The old key name if it changed.

Return value

bool TRUE if they key set successfully, FALSE if not.

1 call to _lockr_set_key()
key_provider_lockr_set_key_value in plugins/key_provider/lockr.inc
Set callback for key_provider plugin.

File

./lockr.module, line 204
Hook implementations and callbacks for lockr.

Code

function _lockr_set_key($key_name, $key_value, $key_label, $encoded = null) {
  $client = lockr_key_client();
  if ($client === FALSE) {
    return FALSE;
  }
  $client = $client
    ->encrypted();
  try {
    return $client
      ->set($key_name, $key_value, $key_label, $encoded);
  } catch (ClientException $e) {
    $body = $e
      ->getMessage();
    $data = json_decode($body, TRUE);
    if (isset($data['title']) && ($data['title'] = 'Not paid')) {
      drupal_set_message(t('NOTE: Key was not set. ' . 'Please go to <a href="@link">Lockr</a> and add a payment method.', array(
        '@link' => 'https://lockr.io/user/add-card',
      )), 'error');
    }
  } catch (\Exception $e) {
  }
  return FALSE;
}