private function remote_get($action, $license) { if ($this->product === NULL) { return NULL; } $api_params = array('edd_action' => $action, 'license' => urlencode($license), 'item_name' => urlencode($this->product), 'url' => urlencode(home_url()), 'plugin_version' => WPFront_User_Role_Editor::VERSION); $response = WPFront_User_Role_Editor::wp_remote_get(add_query_arg($api_params, self::$store_url)); if (is_wp_error($response)) { $this->error = $this->__('ERROR') . ': ' . $this->__('Unable to contact wpfront.com') . '<br />' . $this->__('Details') . ': ' . $response->get_error_message(); return NULL; } $result = json_decode(wp_remote_retrieve_body($response)); if (!is_object($result)) { $this->error = $this->__('ERROR') . ': ' . $this->__('Unable to parse response'); return NULL; } return $result; }
/** * Calls the API and, if successfull, returns the object delivered by the API. * * @uses get_bloginfo() * @uses wp_remote_post() * @uses is_wp_error() * * @param string $_action The requested action. * @param array $_data Parameters for the API action. * @return false||object */ protected function api_request($_action, $_data) { global $wp_version; $data = array_merge($this->api_data, $_data); if ($data['slug'] != $this->slug) { return; } if (empty($data['license'])) { return; } if ($this->api_url == home_url()) { return false; // Don't allow a plugin to ping itself } $api_params = array('edd_action' => 'get_version', 'license' => $data['license'], 'item_name' => isset($data['item_name']) ? $data['item_name'] : false, 'item_id' => isset($data['item_id']) ? $data['item_id'] : false, 'slug' => $this->slug, 'author' => $data['author'], 'url' => home_url()); $api_params['plugin_version'] = $this->version; foreach ($api_params as $key => $value) { $api_params[$key] = urlencode($value); } $request = WPFront_User_Role_Editor::wp_remote_get(add_query_arg($api_params, $this->api_url), array('timeout' => 15, 'sslverify' => false, 'body' => $api_params)); if (!is_wp_error($request)) { $request = json_decode(wp_remote_retrieve_body($request)); } if ($request && isset($request->sections)) { $request->sections = maybe_unserialize($request->sections); } else { $request = false; } return $request; }