public static function save_api_authentication()
 {
     $home_url = str_ireplace(array('http://', 'https://'), '', home_url());
     $connect_nonce_name = 'stream_connect_site-' . sanitize_key($home_url);
     if (!isset($_GET['api_key']) || !isset($_GET['site_uuid'])) {
         wp_die('There was a problem connecting to Stream. Please try again later.', 'stream');
     }
     if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], $connect_nonce_name)) {
         wp_die('Doing it wrong.', 'stream');
     }
     WP_Stream::$api->site_uuid = wp_stream_filter_input(INPUT_GET, 'site_uuid');
     WP_Stream::$api->api_key = wp_stream_filter_input(INPUT_GET, 'api_key');
     // Verify the API Key and Site UUID
     $site = WP_Stream::$api->get_site();
     WP_Stream_API::$restricted = !isset($site->plan->type) || 'free' === $site->plan->type ? 1 : 0;
     if (!isset($site->site_id)) {
         wp_die('There was a problem verifying your site with Stream. Please try again later.', 'stream');
     }
     if (!WP_Stream_API::$restricted) {
         WP_Stream_Notifications::$instance->on_activation();
     }
     update_option(WP_Stream_API::SITE_UUID_OPTION_KEY, WP_Stream::$api->site_uuid);
     update_option(WP_Stream_API::API_KEY_OPTION_KEY, WP_Stream::$api->api_key);
     update_option(WP_Stream_API::RESTRICTED_OPTION_KEY, WP_Stream_API::$restricted);
     do_action('wp_stream_site_connected', WP_Stream::$api->site_uuid, WP_Stream::$api->api_key, get_current_blog_id());
     $redirect_url = add_query_arg(array('page' => self::RECORDS_PAGE_SLUG, 'message' => 'connected'), admin_url(self::ADMIN_PARENT_PAGE));
     wp_redirect($redirect_url);
     exit;
 }
예제 #2
0
 /**
  * Get the details for a specific site.
  *
  * @param array Returns specified fields only.
  * @param bool  Allow API calls to be cached.
  * @param int   Set transient expiration in seconds.
  *
  * @return mixed
  */
 public function get_site($fields = array(), $allow_cache = true, $expiration = 30)
 {
     if (!$this->site_uuid) {
         return false;
     }
     $params = array();
     if (!empty($fields)) {
         $params['fields'] = implode(',', $fields);
     }
     $url = $this->request_url(sprintf('/sites/%s', urlencode($this->site_uuid)), $params);
     $args = array('method' => 'GET');
     $site = $this->remote_request($url, $args, $allow_cache, $expiration);
     if ($site && !is_wp_error($site)) {
         $is_restricted = !isset($site->plan->type) || 'free' === $site->plan->type ? 1 : 0;
         if (self::$restricted !== (bool) $is_restricted) {
             self::$restricted = $is_restricted;
             update_option(self::RESTRICTED_OPTION_KEY, $is_restricted);
         }
     }
     return $site;
 }