The ability to create menus and submenus is necessary for each user who develops :WordPress API. This is due to the fact that they are one of the most important places in building the functionality of themes and plugins. Thanks to these guidelines, each user will be able to understand the main intricacies of creating the menu, opening full access to the options of the theme, and not as it was earlier – only from the menu “Appearance”.
wordpress-rest-apI

A brief look at the API

At this stage we need to learn:

New to options top-level menu;
Add submenu for bookmarks Options “social networking”;
Add submenu for bookmarks “view Options”.

For the implementation of the plans, the user need only 2 commands: add_menu_page (authoring menu) and add_submenu_page (create submenu).

Top-level menu

Initially, you must develop a menu that will be displayed in the administration panel, then “Settings”, it performs 2 main tasks:

Displays the available theme options;
Shows the default settings.

The function takes 7 arguments, the first 5 required: Page_title Capability, Menu_title, Menu_slug, Function_name, Icon_url and Position. All further work is based on the first 5 arguments.

The function call specifies the command add_menu_page. In accordance with the set in the WordPress Codex rules, add menu items to the control panel through the admin_menu hook. With the previous materials, the user must be familiar with all the technical nuances of the team sandbox_example_theme_menu that allows you to add the desired item topic Wednesday appearance.

Adding a submenu

The technique of adding the submenu is almost the same with the addition of the regular menu, except for one caveat – the submenu will belong to the previously created main menu. In this case, the function takes 6 arguments, 5 of which are: Page_title Parent_slug, Menu_title, Capability, Menu_slug, and Function_name. The function itself is different the basic principle of operation. The user needs to create only 2 sub-item is “Options social networking” and “Selecting maps”.

Option mappings

All specified parameters must be properly distributed, with the exception of the function_name may be indicated in the last turn. It is also worth noting that the value coincides with that indicated for add_menu_page.
A key feature of the WordPress API is that after you add the first menu item, WordPress itself will display 2 sub-item. One of which is bound to the previously created sub-item, but the second will duplicate all the functions of the main menu.

Option social networks

All the stages of adding the menu item options social networking is very similar to the action used when creating the item display options. The user only need to replace the header value and the name of the item page and menu using add_submenu_page.
Remains to save your changes and refresh the control panel window. In conclusion, the work done on the monitor in the “Sandbox Theme” will display the sub – Options “social networking”.

Processing functionality of the bookmarks

Experts recommend to use a quick setup guide and reference to the bookmark submenu, select one of the items:
1. The user can override the existing option sandbox_theme_display on reception of optional parameters and then to use an anonymous function, redirecting it to a add_submenu_page all the necessary parameters;
2. Declare a new function that will further display options social services. networks. But this item requires additional configuration from the user: configure tabs without prejudice to the user interface, controlling the size of the code.
Override function will help option sandbox_theme_display.

In conclusion, we summarize that correctly-configured menu system allows you to significantly improve the performance of the entire system. Due to the fact that there is no right or wrong method to create a menu, all the responsibility falls on the user. The most important thing to be careful in placing each item, then a good result will not keep itself waiting.