/** * Calls the API and, if successfull, returns the object delivered by the API. * * @uses get_bloginfo() * @uses wp_remote_post() * @uses is_wp_error() * * @return false||object */ protected function call_remote_api() { // only check if a transient is not set (or if it's expired) if (get_transient($this->product->get_slug() . '-update-check-error') !== false) { return; } // setup api parameters $api_params = array('edd_action' => 'get_version', 'license' => $this->license_key, 'name' => $this->product->get_item_name(), 'slug' => $this->product->get_slug(), 'author' => $this->product->get_author()); // setup request parameters $request_params = array('timeout' => 15, 'sslverify' => false, 'body' => $api_params); // call remote api $response = wp_remote_post($this->product->get_api_url(), $request_params); // wp / http error? if (is_wp_error($response)) { $this->wp_error = $response; // show error to user add_action('admin_notices', array($this, 'show_update_error')); // set a transient to prevent checking for updates on every page load set_transient($this->product->get_slug() . '-update-check-error', true, 60 * 30); // 30 mins return false; } // decode response $response = json_decode(wp_remote_retrieve_body($response)); $response->sections = maybe_unserialize($response->sections); return $response; }
/** * Calls the API and, if successfull, returns the object delivered by the API. * * @uses get_bloginfo() * @uses wp_remote_post() * @uses is_wp_error() * * @return false||object */ protected function call_remote_api() { // only check if a transient is not set (or if it's expired) if (get_transient($this->product->get_slug() . '-update-check-error') !== false) { return false; } // setup api parameters $api_params = array('edd_action' => 'get_version', 'license' => $this->license_key, 'name' => $this->product->get_item_name(), 'slug' => $this->product->get_slug(), 'author' => $this->product->get_author()); // setup request parameters $request_params = array('method' => 'POST', 'body' => $api_params); require_once dirname(__FILE__) . '/class-api-request.php'; $request = new Yoast_API_Request($this->product->get_api_url(), $request_params); if ($request->is_valid() !== true) { // show error message $this->error_message = $request->get_error_message(); add_action('admin_notices', array($this, 'show_update_error')); // set a transient to prevent checking for updates on every page load set_transient($this->product->get_slug() . '-update-check-error', 1, DAY_IN_SECONDS); // 30 mins return false; } // decode response $response = $request->get_response(); $response->sections = maybe_unserialize($response->sections); return $response; }