Options Administration Page

 

See also: Adding Administration Pages wherein it discusses how to turn the options page that you get automatically from this template software into a set of tabs (one of which is the options) where you can add more content.

As described in the Handling Options page, options defined in getOptionsMetaData() automatically appear in an administration options page for the plugin.

Let’s briefly walk through that mechanism and mention some points were you can make changes.

You will find in your template code, in your XXX_Plugin.php file, this code:

1
2
3
4
public function addActionsAndFilters() {
 
    // Add options administration page
    add_action('admin_menu', array(&$this, 'addSettingsSubMenuPage'));

That add_action call installs the options page under the Plugins menu. More specifically, it calls the addSettingsSubMenuPage() function in the XXX_LifeCycle class.

1
2
3
4
public function addSettingsSubMenuPage() {
    $this->addSettingsSubMenuPageToPluginsMenu();
    //$this->addSettingsSubMenuPageToSettingsMenu();
}

Some plugin writers put an options page under the Plugins menu, others put it under the Settings menu. This function chooses the Plugins menu, but you can switch it simply by changing which line is commented out.

The function it calls adds a sub menu page whose content is provided by the settingsPage()

1
2
3
4
5
6
7
8
9
10
protected function addSettingsSubMenuPageToPluginsMenu() {
    $this->requireExtraPluginFiles();
    $displayName = $this->getPluginDisplayName();
    add_submenu_page('plugins.php',
                     $displayName,
                     $displayName,
                     'manage_options',
                     $this->getSettingsSlug(),
                     array(&$this, 'settingsPage'));
}

The settingsPage() is defined in XXX_OptionsManager.php. It is a long method. It includes the code for creating a form with fields for all options. If you want to create a different page, override settingsPage() in XXX_Plugin.php.

 

 

  5 Responses to “Options Administration Page”

  1. any way to assign it to a different one? for example if I’m coding a plugin that will add more options to this other plugin… so I’d need my Sub Menu inserted under that plugin’s top level menu

  2. Archive News & Video for Wednesday, 02 Apr 2014 | …

  3. How would I just convert this to a top level menu with an icon that is near the bottom? I don’t really want it to be a submenu of settings.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>