Menu Addon
This guide applies to the Menu addon v1.1.1.
This addon provides the main navigation menu, the menu builder UI, and the user-options area in the header.
Quick Map
- Menu builder UI:
core/addons/menu/views/console/menu.php - Menu block:
core/addons/menu/views/blocks/menu/default.php - Saved menu data:
storage/menu/<locale>/menu.php - Menu settings UI:
core/addons/menu/views/console/settings.php
How Menu Data Is Stored
The menu builder saves data to a PHP file per locale:
storage/menu/<locale>/menu.php
This file is auto-generated by the builder. Do not edit it manually.
Expose Addon Pages in the Builder (System Links)
Any addon can publish menu-ready links by defining a helper named [addon]_menu_list() in its support/helpers.php.
function my_addon_menu_list(string $locale): array
Entry Format
[
'type' => 'my_addon/page-123',
'title' => 'My Addon Page',
'urlData' => ['my_addon', 'page-123'],
]
- type: unique, stable identifier stored in the menu.
- title: label shown in the builder.
- urlData: array passed to
hp_url()when rendering.
Example Helper
<?php
// core/addons/my_addon/support/helpers.php
function my_addon_menu_list($locale) {
$items = [];
$rows = hp_db_all("SELECT id, title FROM my_addon_pages WHERE locale = ? ORDER BY id DESC", [$locale]);
foreach ($rows as $row) {
$items[] = [
'type' => 'my_addon/page-' . $row['id'],
'title' => $row['title'],
'urlData' => ['my_addon', 'page-' . $row['id']],
];
}
return $items;
}
User Options (Header Area)
The menu block can show a small user-options area. Addons can inject items by providing:
core/addons/<addon>/views/menu-user-options.php
Return Format
<?php
return [
'users' => [],
'not_users' => [],
];
Item Fields
title: label texticon: icon class (example:bi bi-person)url: link target (optional)script: JS for onclick (optional)
Use either url or script. If you use script, include return false; when you want to prevent navigation.
Example
<?php
$menuItems = ['users' => [], 'not_users' => []];
$menuItems['not_users'][] = [
'title' => 'Sign in',
'icon' => 'bi bi-box-arrow-in-right',
'script' => 'windowLogin(); return false;',
];
$menuItems['users'][] = [
'title' => 'My account',
'icon' => 'bi bi-person-circle',
'url' => hp_url($siteContext['urlLocale'], ['my_addon', 'account']),
];
return $menuItems;
Permissions
- Console access:
menu_console_access(standard addon console access key). - Builder actions:
menu_builder_update,menu_builder_items_create,menu_builder_items_edit,menu_builder_items_delete,menu_builder_settings_update.
Tips
- Keep
[addon]_menu_list()fast; it runs whenever the builder loads. - Return an empty array when no items exist. Do not return
null. - Use
hp_t()for translated labels whenever possible.
Guides & Resources
Explore addons, read usage guides, or start developing your own addon
Need More Help?
For complete developer documentation and advanced guides, visit the documentation center.