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.
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
or maybe even another top level menu besides it
oh nevermind my questions, found the answers: https://codex.wordpress.org/Function_Reference/add_submenu_page#Parameters
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.
Override with this function, see https://developer.wordpress.org/reference/functions/add_menu_page/
public function addSettingsMenuItems() {
$this->requireExtraPluginFiles();
$displayName = $this->getPluginDisplayName();
#Main Menu item
add_menu_page(
$displayName,
$displayName,
'manage_options',
$this->getSettingsSlug(),
array(&$this, 'settingsPage'),
'dashicons-heart',
1
);
}
Thanks for building this great tool!
I needed this top-level menu as well. I vote you put it in the core files.