Ack! There has been a sudden surge in plugin releases that make use of the new
add_options_page() function. I think it's great that the community is so interested in extending WordPress this way with such great features. But there's a problem... If your plugin's options page only has one item on it (like a single checkbox or a textbox), then you're taking up a relative ton of real estate on the admin console to enable your options. Take this Amazon ASIN linker plugin for example. It's a great idea. But it you install 4 of these options-light plugins, you've got an Options menu that streches all the way across the screen! It's not a problem with the design of any one plugin, but unless plugin devs start interacting with one another, the issue could escalate. So what's a plugin developer to do? Here's an idea...
SmallOptions is a new plugin that consolidates a bunch of other plugin option pages onto a single "Plugins" option page. Before you poo-poo this idea, check it out... It's optional. That's right. If you code your plugin appropriately, and it's really easy to do so, you can distribute it with or without SmallOptions. If you activate your plugin without SmallOptions enabled, it installs its own Options menu just like it did before. If you activate your plugin with SmallOptions enabled, your options page magically becomes part of the Options | Plugins submenu. I think that's pretty cool. This idea was spawned by email from Graeme, who is working on the GeoMap plugin, which should soon (if it doesn't already) integrate into the Geo plugin that I wrote. GeoMap uses the coordinates that Geo supplies, and so it was a natural fit to combine both interfaces if they're both available. I've packed the SmallOptions plugin with a sample plugin that shows you how to build your plugin so that they can work together. The process is pretty simple:
- Separate your form and div wrapper from the fields that you're using to obtain options. Put these in separate functions inside your plugin, and call the function to output the form innards from inside the function that outputs the form wrapper. (Confused? The code is more clear.)
- When adding your admin menu, check to see if the SmallOptions class exists. If it does, instead of adding your menu to the admin submenu, sink the
small_options_pageaction hook to your form innards function.
- Be sure to handle the storage of your options in the function that produces the form innards. See the sample plugin for a neat method of doing this.
I'm not suggesting that this is the best method for consolidating options pages. After all, converting the Amazon plugin I mentioned above would take a bit more work to get going. (It uses the options.php page to save it's options, which is perfectly valid, but requires that you submit the form to options.php, which SmallOptions won't do.) But something has to happen to keep all of these Options menus from taking over my admin panel! Even if you don't use SmallOptions (and you shouldn't if your plugin has many options to set or requires a more complicated interface) you should check out the sample plugin in the archive, which provides a simple example of building a plugin with its own options page.