Wordpress drill-down admin pages

October 8, 2009

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:
geocache-menu

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

  • Share/Bookmark

Matrix Prof Services: Twitter spammer

October 3, 2009

I haven’t seen this technique before but I already don’t like it. In my email:

MATRIX Prof Services (MATRIXpServices) is now following your tweets on Twitter.

MATRIX Prof Services may not appear in your follower list. MATRIX Prof Services may have decided to stop following you, or the account may have been suspended for a Terms of Service violation.

I added the emphasis to show why MATRIX Prof Services sucks so bad. Of course they are not following me. It’s all automated: Follow someone, autogen the email alert, unfollow. These sumbitches learn a little something about the Internet and they think they know something. What really sucks is they will get thousands of followers.

If you go to their site let me give you a warning: Many jobs listed by these staffing services don’t exist. You heard me. Vapor ware. A staffing service sells people and to sell people you have to have a big supply of resumes. To get resumes one needs to advertise jobs. To get the most resumes with the fewest ads is why so many job listings on Monster and such have so many buzzwords in them, and why you never get a job from them. No real job is going to have 50 proficiency requirements.

If you work through one of these agencies as a contractor, you need to know how much the contract is paying and how much of a cut the agency is taking otherwise you can’t negotiate a fair deal that compensates commiserate with your skill and experience. Most will not tell you; it’s a take it or leave it deal and that’s how you can know you should walk away.

If they do tell, you might be very surprised to find out you’re making $35/hr on a contract that’s paying $65, or more. If you are a straight up 1099 contractor paying your own FICA and have no benefits that’s a whopping shitload of money you are just giving away for nothing in return. If you are struggling to raise a family, $1200/wk for the length of the contract is a lot of dough to trade for someone running a key-word search on a bunch of resumes and making a few phone calls. $30,000 on a 6 month contract. Just half that amount is the difference between making a decent living and just making it. One person should not have to earn a living for 2 people.

Make no mistake, if you take my attitude, you will find it hard to get work because the corporations who use the agencies, which is almost all of them, care more about saving a dollar than they care about the people who work for them and the agencies have a big, big stack of resumes, remember. Whether the next person is half as qualified doesn’t matter to the agency if next person will take $5/hr less, or even a dollar less for that matter. All they have to do is tell the customer the top candidate became unavailable, but they have these other candidates available, many of whom they may or may not have spoken with in months, if ever.

Given the current economic environment and high-profile business failures, corporations might want to take a closer look at how they staff their technical positions. Continue to let morons staff your critical business functions, such as IT, and your enterprise could fail. Just think, a company using Matrox Professional Services might get their next .NET engineer come from a Twitter spam.

I guess there are some reputable IT employment agencies out there but many, if not the majority, have nothing to offer except for taking a huge cut of what YOU earn. Read this earlier post to get a further idea of what I think of I.T. staffing services, and by extension the companies who rely so heavily upon them.

Related posts:

  • Share/Bookmark