/** * Deactivate license */ public function deactivate($id) { // return if a license key isn't set if (!isset($_POST['sp_license_key_' . $id])) { return; } // retrieve the license key $license = trim($_POST['sp_license_key_' . $id]); // get the name of the product $name = $this->licenses[$id]['name']; // data to send in our API request $api_params = array('edd_action' => 'deactivate_license', 'license' => $license, 'item_name' => urlencode($name), 'url' => home_url()); // Call the custom API. $response = wp_remote_post($this->licenses[$id]['url'], array('timeout' => 15, 'sslverify' => false, 'body' => $api_params)); // make sure the response came back okay if (is_wp_error($response)) { SP_Admin_Settings::add_error(__('Sorry, there has been an error.', 'sportspress')); return false; } // decode the license data $license_data = json_decode(wp_remote_retrieve_body($response)); // $license_data->license will be either "deactivated" or "failed" if ($license_data->license == 'deactivated') { delete_site_option('sportspress_' . $id . '_license_status'); SP_Admin_Settings::add_override(__('License deactivated.', 'sportspress')); } else { SP_Admin_Settings::add_error(__('Sorry, there has been an error.', 'sportspress')); } }
/** * Save license key */ public function save() { if (!isset($_POST['sp_save_license'])) { return; } // Prevent default module saving remove_all_actions('sportspress_settings_save_modules'); unset($_POST['sportspress_update_modules']); // Detect license type $this->detect(); // Activate or deactivate license if (isset($_POST['sportspress_pro_license_key_deactivate'])) { $key = $_POST['sportspress_pro_license_key']; if ($key) { $url = 'https://app.sellwire.net/api/1/deactivate_license'; $args = array('license' => $key, 'file' => $this->file); $response = wp_remote_get(add_query_arg($args, $url), array('timeout' => 15, 'sslverify' => false)); if ($response && !is_wp_error($response)) { $body = sp_array_value($response, 'body', '{}'); $json = json_decode($body, true); if (array_key_exists('error', $json)) { SP_Admin_Settings::add_error($json['error']); } elseif (array_key_exists('license', $json)) { SP_Admin_Settings::add_override(__('License deactivated.', 'sportspress')); } delete_site_option('sportspress_pro_license_key'); update_site_option('sportspress_pro_license_status', 'deactivated'); } else { SP_Admin_Settings::add_error(__('Sorry, there has been an error.', 'sportspress')); } } } elseif (isset($_POST['sportspress_pro_license_key'])) { $key = $_POST['sportspress_pro_license_key']; if (!$key) { SP_Admin_Settings::add_error(__('License invalid.', 'sportspress')); return; } $url = 'https://app.sellwire.net/api/1/activate_license'; $args = array('license' => $key, 'file' => $this->file); $response = wp_remote_get(add_query_arg($args, $url), array('timeout' => 15, 'sslverify' => false)); if ($response && !is_wp_error($response)) { $body = sp_array_value($response, 'body', '{}'); $json = json_decode($body, true); if (array_key_exists('error', $json)) { SP_Admin_Settings::add_error($json['error']); } elseif (array_key_exists('license', $json)) { SP_Admin_Settings::add_override(__('License activated.', 'sportspress')); update_site_option('sportspress_pro_license_key', $_POST['sportspress_pro_license_key']); update_site_option('sportspress_pro_license_status', 'valid'); } } else { SP_Admin_Settings::add_error(__('Sorry, there has been an error.', 'sportspress')); } } else { SP_Admin_Settings::add_error(__('License invalid.', 'sportspress')); } }