From 2a2303d1dccc120dd7aa5f6b6ade0f89e0064850 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Nov 2025 07:42:23 +0000
Subject: [PATCH] =Feed block mostly good! Referrals look good to go. Ready for Madi and Heidi to approve

---
 inc/managers/AdminPages.php |   71 +++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 1 deletions(-)

diff --git a/inc/managers/AdminPages.php b/inc/managers/AdminPages.php
index 5145e51..0ae75d4 100644
--- a/inc/managers/AdminPages.php
+++ b/inc/managers/AdminPages.php
@@ -34,7 +34,7 @@
             'icon' => jvbCSSIcon('settings'),
             'position' => 0
         ];
-		$this->subpages = apply_filters('jvbAdminSubpages', []);
+		$this->subpages = get_option(BASE.'adminSubpage', []);
 //        delete_option(BASE.'admin_actions');
 //        delete_option(BASE.'admin_subpages');
 //        $this->getSubpages();
@@ -48,6 +48,9 @@
 		add_filter(BASE.'admin_action_filter', [$this, 'handleCacheActions'], 10, 3);
 
 		add_action('rest_api_init', [$this, 'registerRestRoutes']);
+		// Handle form submissions
+		add_action('admin_init', [$this, 'handleAdminPageSubmission']);
+		add_action('admin_notices', [$this, 'displayAdminNotices']);
     }
 
 	/**
@@ -1113,4 +1116,70 @@
 		</script>
 		<?php
 	}
+
+	public static function addSubpage(string $key, array $value):void
+	{
+		$option = get_option(BASE.'adminSubpage', []);
+		if (empty($option) || !array_key_exists($key, $option)) {
+			$option[$key] = $value;
+			update_option(BASE.'adminSubpage', $option);
+		}
+	}
+
+	/**
+	 * Handle admin page form submissions
+	 * Fires after WordPress admin_init
+	 */
+	public function handleAdminPageSubmission(): void
+	{
+		// Only process on our admin pages
+		if (!isset($_GET['page']) || strpos($_GET['page'], BASE) !== 0) {
+			return;
+		}
+
+		// Check for form submission
+		if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['submit'])) {
+			return;
+		}
+
+		// Verify nonce
+		$nonce_field = BASE . 'admin_page_nonce';
+		if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], $nonce_field)) {
+			add_action('admin_notices', function() {
+				echo '<div class="notice notice-error"><p>Security check failed. Please try again.</p></div>';
+			});
+			return;
+		}
+
+		$page_slug = sanitize_text_field($_GET['page']);
+
+		// Allow other classes to handle their page submissions
+		$result = apply_filters('jvb_admin_page_submission', null, $page_slug, $_POST);
+
+		// Store result in transient for after redirect
+		if (is_array($result)) {
+			set_transient(BASE . 'admin_notice_' . get_current_user_id(), $result, 30);
+		}
+
+		// Redirect to prevent form resubmission (POST-Redirect-GET pattern)
+		wp_safe_redirect(add_query_arg(['page' => $page_slug], admin_url('admin.php')));
+		exit;
+	}
+
+	/**
+	 * Display admin notices from form submissions
+	 */
+	public function displayAdminNotices(): void
+	{
+		$notice = get_transient(BASE . 'admin_notice_' . get_current_user_id());
+
+		if ($notice && is_array($notice)) {
+			delete_transient(BASE . 'admin_notice_' . get_current_user_id());
+
+			$type = $notice['success'] ? 'success' : 'error';
+			$message = $notice['message'] ?? 'Settings saved.';
+
+			echo '<div class="notice notice-' . esc_attr($type) . ' is-dismissible"><p>' . esc_html($message) . '</p></div>';
+		}
+	}
 }

--
Gitblit v1.10.0