backend_extended_menu

Adds custom sections and links to the main menu in the Webasyst 2 interface.

Shop-Script

Input (passed by reference)

$params['menu'] array Main menu data, to which custom sections and items can be added. The keys of added array items must begin with the plugin identifier to avoid conflicts with other plugins. Custom menu sections’ and items’ sub-arrays must contain the following items:

However, if you need to group your menu items in an expandable section and suppose that the same section might also be used ny other plugins then it is advisable not to add your plugin’s identifier to the section ID and rather to use a common identifier such as 'integrations', 'marketplaces', 'social', etc. Before attempting to add such a section, first check whether it already has been added by another plugin whose developer may follow the same idea. An implementation example is shown in the code sample below.

Sub-arrays of plugin’s custom menu sections and items must have the following keys:
$params['menu'][id]['name'] string Localized name of a menu section or item.
$params['menu'][id]['placement'] string Location of the new menu section or item: 'body' (main menu part at the top), 'footer' (auxiliary menu part at the bottom).
$params['menu'][id]['insert_before'] string Identifier of a standard menu section before which a new menu section or item must be added. If not specified then the value of key insert_after is used; if it is missing, too, then the new section or item is added at the end of the menu part specified in key placement.
$params['menu'][id]['insert_after'] string Identifier of a standard menu section after which a new menu section or item must be added. Used only if no value is specified in key 'insert_before'. If not specified then the new section or item is added at the end of the menu part specified in key placement.
$params['menu'][id]['icon'] string HTML/SVG code of a menu section or section.
$params['menu'][id]['url'] string Link URL. Must be empty if the 'submenu' key is not empty — in this case it is a section rather than a simple item.
$params['menu'][id]['submenu'] array Nested link items if this menu element must be an expandable section. Each element of the 'submenu' array must be a sub-array with the following keys:
$params['menu'][id]['name'] string Localized link text.
$params['menu'][id]['url'] string Link URL.

You can also add your custom menu items to default sections by modifying their 'submenu' key.
… your plugin code …

Output

Shop-Script

Plugin code example

PHP

public function backendExtendedMenu(&$params)
{
    $shop_backend_url = wa('shop')->getAppUrl(null, true);

    // Case 1: Add a simple 1st level menu item.
    $params['menu'][$this->id . '_item'] = [
        'name' => _wp("My plugin’s menu item"),
        'icon' => '<i class="fas fa-user"></i>',
        'url' => "{$shop_backend_url}myplugin/",
    ];

    // Case 2: Add 2nd level menu items grouped within a menu section.

    // Case 2.1: Create plugin’s own menu section with menu items.
    $params['menu'][$this->id . '_menu_section'] = [
        'name' => _wp("My menu section"),
        'icon' => '<i class="fas fa-user"></i>',
        'url' => '',
        'submenu' => [
            [
                'name' => _wp('Item 1'),
                'url' => "{$shop_backend_url}myplugin/one/",
            ],
            [
                'name' => _wp('Item 2'),
                'url' => "{$shop_backend_url}myplugin/two/",
            ],
        ],
    ];

    // Case 2.2: Add new items to a common section, which may already have been added by other plugins.
    // This way different plugins can add their menu items within one common section.

    // Example of a menu section ID,
    // which may be used to include menu items provided by different plugins
    // related to various 3rd party integrations.
    $menu_section_id = 'integrations';

    // Step 1: Create the common menu section if it does not exist,
    // i.e., has not yet been added by any other plugin.

    // If a menu section with the specified ID already exists
    // then this code will be ignored.
    shopMainMenu::createSection(
        $params['menu'],
        $menu_section_id,
        _wp("Integrations"),
        [
            // 'insert_before' adds the new section before the built-in "Storefront" section.
            // 'insert_after' will add it after the specified one.
            // Omitting this array item will simply add the new section at the end of the menu.
            'insert_before' => 'storefront',
            // 'body' means the main (top) menu part.
            // 'footer' will add the menu section in the footer (bottom) part.
            'placement' => 'body',
            'icon' => '<i class="fas fa-arrows-alt"></i>',
        ]
    );

    // Step 2: Add new items to the common menu section.
    shopMainMenu::createSubsection(
        $params['menu'],
        $menu_section_id,
        _wp("Item 1"),
        "{$shop_backend_url}myplugin/one/"
    );

    shopMainMenu::createSubsection(
        $params['menu'],
        $menu_section_id,
        _wp("Item 2"),
        "{$shop_backend_url}myplugin/two/"
    );
}