Adding a Toplevel Menu Item

Unless your plugin requires several options pages, it's best to add your options page under the Settings menu as shown in Listing 9-7. However, if you do have a number of separate pages, you can create a toplevel menu item for your plugin as shown in Listing 9-28. This code would replace the first few lines of Listing 9-7.

Listing 9-28. Adding a top-level menu item add_action('admin_menu', 'next_page_add_pages');

function next_page_add_pages() {

add_menu_page('Next Page Options', 'Next Page', 'manage_options', _FILE_,

This add_menu_page() function looks quite a bit like the add_options_page() function in Listing 9-7. The arguments for both functions are:

• Page title: the <title> of your options page

• Heading: the heading shown above your options form

• Capability: the minimum user capability required to access the page (usually manage_options)

• File handle: an identifier for your plugin file (in this case, the file name)

• Options form function: the name of the function that displays the options <form>

• Menu icon (optional in add_menu_page()): you can specify the file location of an icon for your menu item

The results of Listing 9-28 are shown in Figure 9-8.

Figure 9-8. The top-level menu item

Was this article helpful?

0 0

Post a comment