/** * 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 */ private function call_remote_api() { // only check if the failed transient is not set (or if it's expired) if (get_site_transient($this->product->get_prefix() . 'update-request-failed') !== false) { return false; } global $wp_version; // set a transient to prevent failed update checks on every page load // this transient will be removed if a request succeeds set_site_transient($this->product->get_prefix() . 'update-request-failed', 'failed', 10800); // setup api parameters $api_params = array('edd_action' => 'get_version', 'license' => $this->license_manager->get_license_key(), 'item_version' => $this->product->get_version(), 'url' => get_option('home')); $url = add_query_arg($api_params, $this->product->get_api_url()); require_once dirname(__FILE__) . '/class-api-request.php'; $request = new DVK_API_Request($url); if ($request->is_valid() !== true) { // show error message $this->error_message = $request->get_error_message(); add_action('admin_notices', array($this, 'show_update_error')); return false; } // request succeeded, delete transient indicating a request failed delete_site_transient($this->product->get_prefix() . 'update-request-failed'); // decode response $response = $request->get_response(); // check if response returned that a given site was inactive if (isset($response->license_check) && !empty($response->license_check) && (string) $response->license_check !== 'valid') { // deactivate local license $this->license_manager->set_license_status('invalid'); // show notice to let the user know we deactivated his/her license $this->error_message = __('This site has not been activated properly on mc4wp.com and thus cannot check for future updates. Please activate your site with a valid license key.', $this->product->get_text_domain()); add_action('admin_notices', array($this, 'show_update_error')); return false; } // add slug so we can omit it in the request $response->slug = dirname($this->product->get_slug()); $response->sections = maybe_unserialize($response->sections); $response->plugin = $this->product->get_slug(); // store response set_site_transient($this->product->get_prefix() . 'update-response', $response, 10800); return $response; }
/** * Constructor * * @param DVK_Product $product */ public function __construct(DVK_Product $product) { parent::__construct($product); // Check if plugin is network activated. We should use site(wide) options in that case. if (is_admin() && is_multisite()) { if (!function_exists('is_plugin_active_for_network')) { require_once ABSPATH . '/wp-admin/includes/plugin.php'; } $this->is_network_activated = is_plugin_active_for_network($product->plugin_basename); } }
/** * Show a form where users can enter their license key * Takes Multisites into account * * @param bool $embedded * @return null */ public function show_license_form($embedded = true) { // For non-multisites, always show the license form if (!is_multisite()) { parent::show_license_form($embedded); return; } // Plugin is network activated if ($this->is_network_activated && !is_super_admin()) { // We're on the network admin parent::show_license_form_heading(); echo '<p>' . sprintf(__('%s is network activated. Please contact your site administrator to manage the license.', $this->product->get_text_domain()), $this->product->get_item_name()) . '</p>'; } else { parent::show_license_form($embedded); } }
/** * 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 */ private function call_remote_api() { // only check if the failed transient is not set (or if it's expired) if (get_site_transient($this->product->prefix . 'update-request-failed') !== false) { return false; } // set a transient to prevent failed update checks on every page load // this transient will be removed if a request succeeds set_site_transient($this->product->prefix . 'update-request-failed', 'failed', 10800); // setup api parameters $api_params = array('edd_action' => 'get_version', 'license' => $this->license_manager->get_license_key(), 'item_version' => $this->product->version, 'url' => $this->license_manager->is_network_activated ? network_site_url() : get_option('home')); $url = add_query_arg($api_params, $this->product->api_url); require_once dirname(__FILE__) . '/class-api-request.php'; $request = new DVK_API_Request($url); if ($request->is_valid() !== true) { $this->schedule_error($request->get_error_message()); return false; } // request succeeded, delete transient indicating a request failed delete_site_transient($this->product->prefix . 'update-request-failed'); // decode response $response = $request->get_response(); // check if response returned that a given site was inactive if (isset($response->license_check) && !empty($response->license_check) && (string) $response->license_check !== 'valid') { // deactivate local license $this->license_manager->set_license_status('invalid'); // show notice to let the user know we deactivated his/her license $message = __('This site has not been activated properly on mc4wp.com and so cannot check for updates. Please activate your site with a valid license key.', $this->product->text_domain); $this->schedule_error($message); return false; } // update license expiration for renewed license // todo: take lifetime licenses into account (we're not using that yet, but for future ref) if (!empty($response->license_expiration)) { $this->license_manager->set_license_expiry_date($response->license_expiration); } // add slug so we can omit it in the request $response->slug = $this->product->slug; $response->sections = maybe_unserialize($response->sections); $response->banners = (array) $response->banners; $response->plugin = $this->product->plugin_basename; // store response set_site_transient($this->product->prefix . 'update-response', $response, 10800); return $response; }