Skip to content

Menu Configuration

boospot edited this page May 19, 2019 · 1 revision

Menu Config Array have a number of options that can be configured. This config array is an element of main settings config array with array key menu.

All options of field array will look something like this:

$settings_config_array = array(
    //---
    'menu' => array(
        'page_title' => __( 'Plugin Name Settings', 'plugin-name' ),
        'menu_title' => __( 'Plugin Name', 'plugin-name' ),
        'slug'       => 'plugin-name',
        'capability' => 'manage_options',
        // for top level menu
        'position'   => 10,
        'icon'       => 'dashicons-performance',
        // for sub level menu
        'submenu'    => true,
        'parent'     => 'options-general.php',
    ),
    //---
);

There are no required parameters for this menu config as it has default values as if we are creating a setting page for plugin that has a name plugin name

Lets Discuss these parameters one-by-one:

page_title

page_title is used as the page title for Settings page.

  • it should be Text that represent the Settings page title.
  • Too Long and funny character titles should be avoided.
  • Ideally it should be a translatable string.

Default value is 'Plugin Options'

menu_title

menu_title is the text that is shown in the Wordpress Admin menu. Clicking on this admin menu title will open up the Settings page.

  • it should be Text that represent the Settings menu title.
  • It should be short and representing the plugin settings page properly.
  • Ideally it should be a translatable string.

Default value is 'Plugin Options'

slug

slug is the parameter that defines the url slug of the Setting page in wordpress admin.

  • it should be URL friendly string.
  • Ideally it should contain only letters, numbers , dashes and underscores
  • It should be unique so that it does not create conflict in WordPress admin slugs

Default Value is generated by running the page_title through sanitize_title function.

capability

capability parameter is the user capability to manage this Settings page. Complete list of user capabilities can be found on Wordpress Codex page: Roles and Capabilities.

Default value is manage_options

position

position parameter is used to configure Menu position of the plugin Settings page in Wordpress Admin screen.

This parameter is only useful if plugin menu is configured to be top-level menu item. i.e. 'submenu' => false

Wordpress menu items position details can be found on Wordpress Codex Menu Structure

Default value is 100 i.e after the separator after Settings menu item.

icon

icon parameter is used to define icon for the menu item.

For more details, you may check the List of dashicons code.

Default value is empty that shows the default cog icon for menu item.

submenu

submenu parameter is used to configure if the plugin menu to shown as top-level or as a sub-level menu item.

Default is false that results in menu item as top-level menu item. By just configuring it true, the menu item will appear under Settings menu item in WordPress admin.

parent

parent parameter is the slug name for the parent menu (or the file name of a standard WordPress admin page). its used to define the parent menu item under which the plugin menu item should be shown. It is useful only when plugin menu is configured as sub-menu item.

Here are the slugs for WordPress default menu items:

Dashboard:  'index.php'
Posts:      'edit.php'
Media:      'upload.php'
Pages:      'edit.php?post_type=page'
Comments:   'edit-comments.php'
Appearance: 'themes.php'
Plugins:    'plugins.php'
Users:      'users.php'
Tools:      'tools.php'
Settings:   'options-general.php'
Network Settings: 'settings.php'
Custom Post Type: 'edit.php?post_type=your_post_type'

Default value is 'options-general.php' that will show the menu item under Settings menu item in WordPress admin.