/** * Create the key. */ public function create_key() { if (!isset($_POST['itelic-add-new-key']) || !isset($_POST['_wpnonce'])) { return; } if (!wp_verify_nonce($_POST['_wpnonce'], 'itelic-add-new-key')) { $this->message[View::NOTICE_ERROR] = __("Request expired. Please try again.", Plugin::SLUG); return; } if (!current_user_can('manage_options')) { $this->message[View::NOTICE_ERROR] = __("You don't have permission to do this.", Plugin::SLUG); return; } if (empty($_POST['product'])) { $this->message[View::NOTICE_ERROR] = __("You must select a product.", Plugin::SLUG); return; } $product = absint($_POST['product']); if (empty($_POST['username'])) { $customer = absint($_POST['customer']); } else { $customer = wp_insert_user(array('user_login' => $_POST['username'], 'user_email' => $_POST['email'], 'first_name' => $_POST['first'], 'last_name' => $_POST['last'], 'user_pass' => wp_generate_password(24, true, true))); if (is_wp_error($customer)) { $this->message[View::NOTICE_ERROR] = $customer->get_error_message(); return; } } $activations = intval($_POST['activations']); $expiration = \ITELIC\make_local_time($_POST['expiration']); $key = $_POST['license']; $paid = $_POST['paid']; $args = array('key' => $key, 'product' => $product, 'customer' => $customer, 'paid' => $paid, 'limit' => $activations, 'expires' => \ITELIC\convert_local_to_gmt($expiration)); /** * Filters the args used to create a new license key. * * @since 1.0 * * @param array $args */ $args = apply_filters('itelic_add_new_license_args', $args); $key = itelic_create_key($args); /** * Fires when a new license key is created from the add new form. * * @since 1.0 * * @param Key $key */ do_action('itelic_add_new_license_save', $key); if (is_wp_error($key)) { $this->message[View::NOTICE_ERROR] = $key->get_error_message(); } else { /** * Determine whether or not to send WP's new user notification * when a key is manually created from the add new license key page. * * @since 1.0 * * @param bool $send * @param Key $key */ $send_notification = apply_filters('itelic_add_new_license_send_new_user_notification', true, $key); if ($send_notification) { wp_new_user_notification($customer, null, 'both'); } wp_redirect(itelic_get_admin_edit_key_link($key->get_key())); exit; } }
/** * Perform the update on the key. * * @since 1.0 * * @param Key $key * @param string $prop * @param string $val * @param string $nonce * * @return bool * * @throws \InvalidArgumentException */ public function do_update(Key $key, $prop, $val, $nonce) { if (!wp_verify_nonce($nonce, "itelic-update-key-{$key->get_key()}")) { throw new \InvalidArgumentException(__("Sorry, this page has expired. Please refresh and try again.", Plugin::SLUG)); } if (!current_user_can('manage_options')) { throw new \InvalidArgumentException(__("Sorry, you don't have permission to do this.", Plugin::SLUG)); } switch ($prop) { case 'status': $key->set_status($val); break; case 'max': $key->set_max($val); break; case 'expires': $date = \ITELIC\make_local_time($val); $date = \ITELIC\convert_local_to_gmt($date); $key->set_expires($date); break; default: throw new \InvalidArgumentException(__("Invalid request format.", Plugin::SLUG)); } return true; }
/** * This saves the value. * * @since 1.0 */ public function save_feature_on_product_save() { // Abort if we don't have a product ID $product_id = empty($_POST['ID']) ? false : $_POST['ID']; if (!$product_id) { return; } $data = $_POST['itelic_readme']; $data['enable'] = isset($data['enable']) ? it_exchange_str_true($data['enable']) : false; $last_updated = \ITELIC\make_local_time($data['last_updated']); $data['last_updated'] = $last_updated->getTimestamp(); it_exchange_update_product_feature($product_id, $this->slug, $data); }