EDD_SL_Plugin_Updater::api_request PHP Method

api_request() private method

Calls the API and, if successfull, returns the object delivered by the API.
private api_request ( string $_action, array $_data ) : false | object
$_action string The requested action.
$_data array Parameters for the API action.
return false | object
    private 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' => $data['slug'], 'author' => $data['author'], 'url' => home_url());
        $request = wp_remote_post($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;
    }

Usage Example

 protected function api_request($_action, $_data)
 {
     $time_key = $this->slug . '-plugin_updater_api_request_last_checked';
     $api_key = $this->slug . '-plugin_updater_api_request';
     $entity = new WPFront_User_Role_Editor_Entity_Options();
     $time = $entity->get_option($time_key);
     if ($time === NULL || $time < time() - 6 * 3600) {
         $api = NULL;
     } else {
         $api = $entity->get_option($api_key);
     }
     if ($api === NULL) {
         $api = parent::api_request($_action, $_data);
         if ($api) {
             $entity->update_option($api_key, serialize($api));
             $entity->update_option($time_key, time());
         }
     } else {
         $api = unserialize($api);
     }
     return $api;
 }