$value) { if (is_array($value)) { natsort($value); foreach ($value as $v2) { $pairs[] = ('' === $v2) ? "$key=0" : "$key=$v2"; } } else { $pairs[] = ('' === $value) ? "$key=0" : "$key=$value"; } } $string = implode('&', $pairs); return $string; } /** * Takes a token response from a request token call, then puts it in an appropriate array. * * @param $response * @return array */ abstract public function parse_token($response): array; /** * Saves the token in the authentication options. Used only by Flickr and SmugMug; invoked via the Authentication screen. * Transients don't need to be saved as Flickr and SmugMug don't need them. * * @param $token */ public function save_token($token) { if (current_user_can('edit_theme_options') && check_ajax_referer($this->provider . '-request-token-' . $this->api_secret)) { $photonic_authentication = get_option('photonic_authentication'); if (!isset($photonic_authentication)) { $photonic_authentication = []; } $photonic_authentication[$this->provider] = $token; update_option('photonic_authentication', $photonic_authentication); } } /** * Fetches a token from authentication options * * @return array|null */ public function get_cached_token() { $transient_token = get_transient('photonic_' . $this->provider . '_token'); $photonic_authentication = get_option('photonic_authentication'); if (false !== $transient_token) { return $transient_token; } if (!empty($photonic_authentication) && isset($photonic_authentication[$this->provider])) { $transient_expiry = $photonic_authentication[$this->provider]['oauth_token_created'] + $photonic_authentication[$this->provider]['oauth_token_expires'] - time(); set_transient('photonic_' . $this->provider . '_token', $photonic_authentication[$this->provider], $transient_expiry); return $photonic_authentication[$this->provider]; } return null; } }