/** * 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; }