I was gaining momentum on the Geocache Manager WordPress plugin last week after solving a couple of longstanding problems with unauthenticated Ajax calls and a few Javascript quirks with Internet Explorer when yet another pesky problem surfaces. When I say pesky it means that I have been fooling around with it for several days without zeroing in on a solution, thus making zero headway on the project. To make matters worse, the problem lies with a feature that has existed from the beginning and had worked until I upgraded from WordPress Mu 2.7 to 2.8.4a last week.
In the admin panel I have a custom top level menu with two entries: a page for the map management and a page for options. The following bit of code…
function addAdminMenu(){
add_action('admin_menu', array(&$this, 'gcgc_plugin_menu'));
}
function gcgc_plugin_menu() {
$gcgc_relpath = str_replace('\\','/',dirname(__FILE__));
$parent = $gcgc_relpath.'/gcgc-admin-form.php';
add_menu_page('Private Geocache Manager', 'Geocache', 1,
$parent, array(&$this, 'gcgc_admin_page'));
add_submenu_page($parent, 'Geocache Options', 'Options', 1,
'gcgc_options', array(&$this, 'gcgc_options_page'));
}
function gcgc_options_page(){
$gcgc_relpath = str_replace('\\','/',dirname(__FILE__));
include($gcgc_relpath.'/gcgc-options-form.php');
}
function gcgc_admin_page() {
$gcgc_relpath = str_replace('\\','/',dirname(__FILE__));
include($gcgc_relpath.'/gcgc-admin-form.php');
}
…will give you a menu like so:

That all works. The geocache admin form lists all the courses defined and for each course there is a link to load a new admin page for that course. This is basic functionality that has existed since the 1st week of development and suddenly the link no longer works. The link now generates a redirect to a sub-blog with a page not found. WTF! Where do you start at on that.
I admit I am a little weak on WordPress redirects and I am having a difficult time understanding why the redirect would go to a sub-blog in the WordPress Mu installation instead of the current blog. But aside from that I don’t understand why it started issuing a redirect in the first place when the code that generates the link hasn’t changed in like five months.
UPDATE: I fixed the redirect problem by deleting the sub-blogs. Now I am just getting a mangled url, like so:
http://gulfcoastgeocache.com/wp-admin/?c=1
So let's go over what I am thinking so far. I am of course using the wp-admin framework and have the faulty link set up similar to the pages accessed from the admin menu. The URL on the Geocache admin link is:
.../wp-admin/admin.php?page=private-geocache-manager/gcgc-admin-form.php
Then on that page there is an entry for each geocache course and each course has an anchor link to its own admin page, like so:
<a href=".../wp-admin/admin.php?
page=private-geocache-manager/gcgc-admin-cache.php&id=20">
Geocache Name</a>
After checking the usual suspects -- verifying paths, searching for typos, confirming no function parameters had been inadvertently changed -- the only thing I can think of is that the drill-down admin page was working previously only due to a flaw in previous WordPress. I remember when putting it in that it seemed easy. Too easy.
Over the past few days I've done quite a bit of searching using every term anyone could probably think of having to do with registering an admin page that is not on a menu. Compared to other development platforms out there (Make no mistake, WordPress is a development platform) there just is not that much in-depth technical documentation outside of your standard stuff. There are many redundant articles on adding an admin menu, for example, but not much on adding a multi-page, drill-down admin system. You have to figure that out on your own. Either not many people are doing advanced development or they are very tight-lipped about their stuff.
This morning I finally came upon an article that at least verifies my thinking:
WordPress 2.8.1 contains changes to improve the security of plugins by ensuring that only correctly registered plugin pages can be accessed as well as only showing the link to the page to users who have the capability required in the add_x_page call.
The article makes no mention of dynamically created sub-pages accessed by means other than the WordPress menu structure but down in the comments I find a fellow traveler:
I already have add_action(’admin_menu’, ‘FUNCTION’); for my main settings page. However, there’s a plugin page which is not a menu link (but an inside plugin page which is referenced when the plugin settings are saved).
And the answer to my problem, if not the solution:
You cannot just link to pages that are not registered as this would make it easy to load up files which should not be loaded so you have two choices to fix your plugin.
He goes onto say that the workaround is to use a WordPress admin action hook or a call back to the main page to process the main form submissions.
I like to keep my pages small and manageable and this plugin will ultimately have half a dozen admin pages when all the features are added. As of now there are only three. But since I want many small files instead on one big file here is what I am going to do: I am going to create a main admin container page that includes the proper admin panel when loading based on the URL. Should have seen this problem coming and set up like this in the first place. Oh well. I'll report back when I get the changes complete.
Read the follow-up:
WordPress drill-down admin pages II