'error', 'message' => 'Key name is required.'], 60); wp_redirect(admin_url('admin.php?page=asktam-mcp')); exit; } global $wpdb; $table = $wpdb->prefix . 'asktam_mcp_keys'; $rawKey = \AskTamMCP\Core\Auth::generateKey(); $wpdb->insert($table, [ 'name' => $name, 'api_key' => $rawKey, 'scopes' => implode(',', $scopes), 'created_at' => current_time('mysql'), 'is_active' => 1, ]); // Store raw key in transient so we can show it once on next page load set_transient('asktam_mcp_new_key_' . get_current_user_id(), $rawKey, 120); wp_redirect(admin_url('admin.php?page=asktam-mcp&mcp_created=1')); exit; } public function handleRevoke(): void { if (!current_user_can('manage_options')) wp_die('Unauthorized'); $id = (int) ($_POST['key_id'] ?? 0); check_admin_referer('asktam_mcp_revoke_' . $id, '_wpnonce_mcp'); global $wpdb; $table = $wpdb->prefix . 'asktam_mcp_keys'; $wpdb->update($table, ['is_active' => 0], ['id' => $id]); set_transient('asktam_mcp_notice', ['type' => 'success', 'message' => 'API key revoked.'], 60); wp_redirect(admin_url('admin.php?page=asktam-mcp')); exit; } /** * Show new-key banner via admin_notices so the raw key appears once. */ public function showNotices(): void { $screen = get_current_screen(); if (!$screen || strpos($screen->id, 'asktam-mcp') === false) return; // General notices (errors, simple confirmations) $notice = get_transient('asktam_mcp_notice'); if ($notice) { delete_transient('asktam_mcp_notice'); $class = $notice['type'] === 'error' ? 'notice-error' : 'notice-success'; printf('

%s

', esc_attr($class), esc_html($notice['message'])); } // New key reveal (shown once) $newKey = get_transient('asktam_mcp_new_key_' . get_current_user_id()); if ($newKey && isset($_GET['mcp_created'])) { delete_transient('asktam_mcp_new_key_' . get_current_user_id()); ?>

✓ API key created. Copy it now — it won't be shown in full again.