[wp-hackers] Change in plugin Options page handling

Owen Winkler ringmaster at midnightcircus.com
Thu Feb 3 16:08:41 GMT 2005


After applying the patch and messing around a little, I can answer these:

> Now, do plugins need to have a totally seperate options page? (what's
> ml_options_page?)

They don't *need* an options page at all, but for plugins that do need 
to supply an options interface to users, this plugin hook supplies that 
functionality.

ml_options_page is a function in that specific plugin that supplies the 
output for its custom options page.

> How would a plugin developer load his option page, and how would an
> options page be added for all the different plugins?

Technically, you can get an option page to display by specifying the 
plugin filename on the URL querystring like so:

example.com/wp-admin/admin.php?page=pluginfilename.php

You can still use the add_management_page() and add_options_page() to 
produce menus that use the correctly formed URL.  These functions only 
initialize the menu system, and don't affect the construction of the 
page itself.

> I am sorry if I got it wrong, but to add_actions(something) don't you
> need a "something" hook? Does WordPress automatically add hooks like
> options_page_<name-of-plugin-file> each time a new plugin is
> activated?

Yes, WordPress automatically generates the hooks based on the active 
plugins.

> I haven't taken a look at the new code, and so I thought it would be a
> good time to ask questions that may fill a few gaps in the
> description.
> 
> An example of how this is to be used, with a mention of how it works
> internally within WordPress, would be great.

Er, here's a working example of use:
http://dev.wp-plugins.org/file/geo/trunk/geo.php

The options_page_geo() class member is used to produce an options page 
for the plugin.  When Geo is activated as a plugin, WordPress creates a 
hook called 'options_page_geo'.  This hook is hooked by the plugin using 
the line:

add_action('options_page_geo', array('Geo', 'options_page_geo'));

This tells the plugin system to execute the static member 
Geo::options_page_geo() to produce page output whenever the page 
"wp-admin/admin.php?page=geo.php" is requested.

This line begins adding the new menu to the Options submenu:

add_action('admin_menu', array('Geo', 'admin_menu'));

This tells the plugin system to execute the static member 
Geo::admin_menu when the admin menu is being constructed.  The code in 
that member is simply:

add_options_page(__('Geo Location Manager', 'Geo'), __('Geo Info', 
'Geo'), 5, 'geo.php');

Which creates a menu labeled "Geo Info", with a page title of "Geo 
Location Manager", only for users of level 5 or better, pointing to the 
geo.php file, as necessary/shown above.

It's possible to make a simpler sample that does not use a class (for 
reducing namespace collision issues), but it seems to me that anything 
that uses an options page is probably going to have enough functions to 
warrant such protection.  Anyway, this is the code I had sitting around 
to mess with.

Owen



More information about the hackers mailing list