function mexp_instagram_user_credentials_callback($credentials) { if (!class_exists('Keyring')) { return $credentials; } // Check that the instagram service is setup $keyring = Keyring::init()->get_service_by_name('instagram'); if (is_null($keyring)) { return $credentials; } $keyring_store = Keyring::init()->get_token_store(); // Hacky time, Keyring is designed to handle requests, but we're just stealing its access_token. if (method_exists($keyring_store, 'get_tokens_by_user')) { // The wpcom version uses the get_tokens_by_user method $users_tokens = $keyring_store->get_tokens_by_user(get_current_user_id()); if (in_array('instagram', $users_tokens)) { $credentials['access_token'] = $users_tokens['instagram'][0]->token; } } elseif (method_exists($keyring_store, 'get_tokens')) { // The released version uses the get_tokens method $users_tokens = $keyring_store->get_tokens(array('service' => 'instagram', 'user_id' => get_current_user_id())); if (count($users_tokens) > 0) { $credentials['access_token'] = $users_tokens[0]->token; } } return $credentials; }
/** * Get the user's API token. * * @access public * * @return string The user's token */ public function get_token() { $token = get_option('eventbrite_api_token'); if (empty($token)) { return false; } $this->set_token(Keyring::init()->get_token_store()->get_token(array('type' => 'access', 'id' => $token))); $this->eventbrite_external_id = defined('IS_WPCOM') && IS_WPCOM ? $this->token->get_meta('external_id') : $this->token->get_meta('user_id'); return $this->token; }
/** * Generic error handler/trigger. * @param String $str Informational message (user-readable) * @param array $info Additional information relating to the error. * @param boolean $die If we should immediately die (default) or continue */ static function error($str, $info = array(), $die = true) { $keyring = Keyring::init(); $keyring->errors[] = $str; do_action('keyring_error', $str, $info, isset($this) ? $this : null); if ($die) { wp_die($str, __('Keyring Error', 'keyring')); exit; } }
function __construct() { $this->keyring = Keyring::init(); parent::__construct(array('singular' => 'connection', 'plural' => 'connections', 'screen' => $this->keyring->admin_page)); $this->items = Keyring::get_token_store()->get_tokens(); }