page_slug = 'wpc7_redirect'; $this->api = new Qs_Api(); add_action('admin_menu', array($this, 'create_plugin_settings_page')); add_action('admin_init', array($this, 'wpcf7r_register_options')); add_filter('plugin_row_meta', array($this, 'register_plugin_links'), 10, 2); } /** * Deactivate the license - Disabled on v2.0 */ public function deactivate_license() { $serial = WPCF7r_Utils::get_serial_key(); $activation_id = WPCF7r_Utils::get_activation_id(); $this->api->deactivate_liscense($activation_id, $serial); $this->reset_activation(); wp_redirect(WPCF7r_Utils::get_plugin_settings_page_url()); } /** * Register plugin options */ public function wpcf7r_register_options() { $this->fields = array(); // $this->add_license_section(); $this->add_settings_section(); foreach ($this->fields as $field) { $args = array(); add_settings_field($field['uid'], $field['label'], array($this, 'field_callback'), $this->page_slug, $field['section'], $field); // $args['sanitize_callback'] = array($this, 'validate_serial_key'); register_setting($this->page_slug, $field['uid'], $args); } } public function add_settings_section() { add_settings_section('settings_section', __('Global Settings', 'wpcf7-redirect'), array($this, 'section_callback'), $this->page_slug); $this->fields = array_merge( $this->fields, array( array( 'uid' => 'wpcf_debug', 'label' => 'Debug', 'section' => 'settings_section', 'type' => 'checkbox', 'options' => false, 'placeholder' => '', 'helper' => '', 'supplemental' => __('This will open the actions post type and display debug feature.', 'wpcf7-redirect'), 'default' => '', ), ) ); } /** * add_license_section - Deprecated */ public function add_license_section() { add_settings_section('serial_section', __('License Information', 'wpcf7-redirect'), array($this, 'section_callback'), $this->page_slug); $this->fields = array_merge( $this->fields, array( array( 'uid' => 'wpcf7r_serial_number', 'label' => 'Serial Number', 'section' => 'serial_section', 'type' => 'text', 'options' => false, 'placeholder' => 'Type your serial here', 'helper' => '', 'supplemental' => __('This process will send your serial/domain to a 3rd party validation server to validate the key authenticity', 'wpcf7-redirect'), 'default' => '', ), ) ); return $fields; } /** * Validate serial key process * * @param $serial */ public function validate_serial_key($serial) { if (!$serial) { return; } $activation_id = WPCF7r_Utils::get_activation_id(); if (!$activation_id) { $is_valid = $this->api->activate_serial($serial); } else { $is_valid = $this->api->validate_serial($activation_id, $serial); } // serial was not valid if (is_wp_error($is_valid)) { $message = $is_valid->get_error_message(); if (is_object($message) && isset($message->license_key)) { $message = $message->license_key[0]; } add_settings_error( 'wpcf7r_serial_number', 'not-valid-serial', $message, 'error' ); $this->reset_activation(); return false; } elseif (!$activation_id) { // serial was valid, update the activation key for future validation $this->set_activation($is_valid->data); } if (isset($_GET['deactivate'])) { return ''; } return $serial; } /** * Delete all activation data - use in case activation validation or activation returns an error */ public function reset_activation() { delete_option('wpcf7r_activation_id'); delete_option('wpcf7r_activation_expiration'); delete_option('wpcf7r_activation_data'); WPCF7r_Utils::delete_serial_key(); } /** * Set all data related with the plugin activation * * @param $validation_data */ public function set_activation($validation_data) { update_option('wpcf7r_activation_id', $validation_data->activation_id); update_option('wpcf7r_activation_expiration', $validation_data->expire); update_option('wpcf7r_activation_data', $validation_data); } /** * A function for displaying a field on the admin settings page */ public function field_callback($arguments) { $value = get_option($arguments['uid']); // Get the current value, if there is one if (!$value) { // If no value exists $value = $arguments['default']; // Set to our default } // Check which type of field we want switch ($arguments['type']) { case 'text': // If it is a text field case 'password': printf('', $arguments['uid'], $arguments['type'], $arguments['placeholder'], $value); break; case 'checkbox': // If it is a text field $checked = checked($value, '1', false); printf('', $arguments['uid'], $arguments['type'], $arguments['placeholder'], '1', $checked); break; } $helper = $arguments['helper']; $supplimental = $arguments['supplemental']; // If there is help text if ($helper) { printf(' %s', $helper); // Show it } // If there is supplemental text if ($supplimental) { printf('
%s
', $supplimental); // Show it } } /** * Main call for creating the settings page */ public function create_plugin_settings_page() { // Add the menu item and page $page_title = 'Redirection settings'; $capability = 'manage_options'; $callback = array($this, 'plugin_settings_page_content'); add_submenu_page( 'wpcf7', $page_title, $page_title, $capability, $this->page_slug, $callback ); } /** * The setting page template HTML */ public function plugin_settings_page_content() { ?>