function rp4wp_premium_deactivate_plugin() { include_once plugin_dir_path(RP4WP_PLUGIN_FILE) . 'classes/class-updater-key-api.php'; // Plugin slug $plugin_slug = str_replace('.php', '', basename(RP4WP_PLUGIN_FILE_INSTALLER)); // Get license options $license_options = get_option('rp4wp_license', array()); // Only continue if there's a license key if (!isset($license_options['licence_key'])) { return; } // Deactivate license RP4WP_Updater_Key_API::deactivate(array('api_product_id' => $plugin_slug, 'licence_key' => $license_options['licence_key'])); // Always delete license related options delete_option('rp4wp_license'); delete_site_transient('update_plugins'); }
/** * Handle errors from the API * * @param array $errors */ public function handle_errors($errors) { // loop through errors foreach ($errors as $error_key => $error) { // add error to WP $this->add_error($error, $error_key); if ('no_activation' == $error_key) { // Deactivate license on server RP4WP_Updater_Key_API::deactivate(array('api_product_id' => $this->plugin_slug, 'license_key' => $this->api_key)); // Set local activation status to false RP4WP_Updater_Key_API::set_activated(false); } } }
/** * Sanitize the option value * * @param array $post_data * * @since 1.1.0 * @access public * * @return array */ public function sanitize_option($post_data) { /** * @todo When options are moved to a more OOP setup, each input class will have their own sanitization method. */ if (false !== strstr($this->page, 'rp4wp_general_')) { // Unset automatic_linking if not set in post if (!isset($post_data['automatic_linking'])) { $post_data['automatic_linking'] = 0; } // automatic_linking must be an integer if (isset($post_data['automatic_linking'])) { $post_data['automatic_linking'] = intval($post_data['automatic_linking']); } // automatic_linking_post_amount must be an integer if (isset($post_data['automatic_linking_post_amount'])) { $post_data['automatic_linking_post_amount'] = intval($post_data['automatic_linking_post_amount']); } // Excerpt length must be an integer if (isset($post_data['excerpt_length'])) { $post_data['excerpt_length'] = intval($post_data['excerpt_length']); } } else { if (false !== strstr($this->page, 'rp4wp_license')) { // License sanitize callback try { $plugin_slug = str_replace('.php', '', basename(RP4WP_PLUGIN_FILE)); // Try to activate the license if (false == RP4WP_Updater_Key_API::is_activated()) { $license_key = sanitize_text_field($post_data['licence_key']); $email = sanitize_text_field($post_data['email']); if (empty($license_key)) { throw new Exception('Please enter your license key.'); } if (empty($email)) { throw new Exception('Please enter the email address associated with your license.'); } $activate_results = json_decode(RP4WP_Updater_Key_API::activate(array('email' => $email, 'license_key' => $license_key, 'api_product_id' => $plugin_slug)), true); if (!empty($activate_results['activated'])) { // Set post data from API respond $post_data['licence_key'] = $license_key; $post_data['email'] = $email; // Add successful activation messages $message_handler = new RP4WP_Manager_Settings_Messages(); $message_handler->add_message('License successfully activated', 'updated'); // Set local activation status to true RP4WP_Updater_Key_API::set_activated(true); } elseif ($activate_results === false) { throw new Exception('Connection failed to the License Key API server. Try again later.'); } elseif (isset($activate_results['error_code'])) { throw new Exception($activate_results['error']); } } else { // Get license options $license_options = get_option('rp4wp_license', array()); // Throw error if there's no license key in the database if (isset($license_options['licence_key']) && '' != $license_options['licence_key']) { // Try to deactivate the license RP4WP_Updater_Key_API::deactivate(array('api_product_id' => $plugin_slug, 'license_key' => $license_options['licence_key'])); // Set local activation status to false RP4WP_Updater_Key_API::set_activated(false); // Set the correct license key as post data $post_data['licence_key'] = $license_options['licence_key']; } } } catch (Exception $e) { // Add exception messages as error message to message handler $message_handler = new RP4WP_Manager_Settings_Messages(); $message_handler->add_message($e->getMessage(), 'error'); // Set local activation status to false RP4WP_Updater_Key_API::set_activated(false); } } else { if (false !== strstr($this->page, 'rp4wp_configurator')) { // delete components transient delete_transient(RP4WP_Constants::TRANSIENT_COMPONENTS); // delete component css transient delete_transient(RP4WP_Constants::TRANSIENT_COMPONENT_CSS); // Set correct component order in configuration $config = json_decode($post_data['configuration']); if (null !== $config && count($config) > 0) { // sort components usort($config, array($this, 'sort_components')); $post_data['configuration'] = json_encode($config); } // Remove tags from custom CSS if ('' != $post_data['css']) { $post_data['css'] = strip_tags($post_data['css']); } } else { if (false !== strstr($this->page, 'rp4wp_words')) { // delete joined words transient delete_transient(RP4WP_Constants::TRANSIENT_JOINED_WORDS); // delete extra ignored words transient delete_transient(RP4WP_Constants::TRANSIENT_EXTRA_IGNORED_WORDS); } } } } return $post_data; }