Anatomy Of A WordPress Plugin: Adding Admin Submenus For Options Pages

WordPressI have not yet written a plugin for WordPress that is complex enough to require the settings to be broken down over multiple pages in the Admin area, but this is something that is possible to do fairly easily.

In the last post we covered adding a link on the menu using the add_options_page function.

This function works for a single options page, but this function doesn’t work for submenus.

Instead we need to use add_menu_page to add the top level menu and add_submenu_page.

As with add_options_page, these functions are called using the add_action function with the admin_menu hook to call a custom function.

The code below shows the two functions being called for a mocked up example:

add_action("admin_menu", "azc_create_menus");

function azc_create_menus() {
    add_menu_page( "azurecurve Menu"
			, "azurecurve Menu"
			, 0
			, "azurecurve-menu-slug"
			, "azurecurveMenuPageFunction"
			, plugins_url( '/images/favicon.ico', __FILE__ ) );
    
	add_submenu_page( "azurecurve-menu-slug"
			, "azurecurve Submenu"
			, "azurecurve Submenu"
			, 0
			, "azurecurve-submenu-slug"
			, "azurecurveSubmenuPageFunction" );
}

Continue reading

Anatomy Of A WordPress Plugin: Adding Admin Menu For Options Page

WordPressAll but the most simple of WordPress plugins will require an options page in the Admin area which will need to be made accessible to the admin users. The main way this would be done is to add an entry to the admin menu.

This is done using the add_action function with the admin_menu hook to call a custom function.

This custom function then uses the add_options_page function to add the options page to the Settings menu.

The code below is from my RSS Suffix plugin where a menu option called azurecurve RSS Suffix is calling a function called azc_rss_config_page:

add_action( 'admin_menu', 'azc_rss_settings_menu' );

function azc_rss_settings_menu() {
	add_options_page( 'azurecurve RSS Suffix'
						,'azurecurve RSS Suffix'
						,'manage_options'
						,'azurecurve-rss-suffix'
						, 'azc_rss_config_page' );
}

Continue reading