AdminMenu Class
Programmable Admin Navigation Class
The AdminMenu class is the centralized navigation registry for the GeniXCMS administration panel. Introduced in v2.0.0, it replaces all hardcoded HTML navigation items with a programmable, data-driven system that allows modules and themes to inject, reorder, or remove menu items without touching any core template files.
⚡ How It Works
AdminMenu is bootstrapped automatically by the System constructor: new AdminMenu() is called after all modules and themes are loaded. This means every module registered via Hooks::attach('init', ...) can safely add menu items during the system's own startup sequence.
System::__construct()
└── new Mod() ← Module function.php files run (can call AdminMenu::add())
└── new Theme() ← Theme function.php runs (can call AdminMenu::add())
└── Hooks::run('init')
└── new AdminMenu() ← Registers core menu + fires 'admin_menu_boot' hook
📐 Menu Item Schema
Every menu item is defined as a PHP associative array with the following keys:
| Key | Type | Default | Description |
|---|---|---|---|
id |
string |
menu_xxxx |
Unique identifier. Used for active-state detection. |
label |
string |
'Menu Item' |
Display text. Always wrap in _() for i18n. |
icon |
string |
'bi bi-circle' |
Bootstrap Icons class (e.g., bi bi-cart3). |
url |
string |
'#' |
Target URL. Relative to the admin directory. |
access |
int |
6 |
Minimum user level required to see this item. |
position |
string |
'external' |
Navigation region. See Positions below. |
order |
int |
50 |
Sort weight. Lower numbers appear higher/earlier. |
children |
array |
[] |
Optional sub-items for dropdown/collapsible menus. |
Access Levels
| Value | Role |
|---|---|
0 |
Administrator |
1 |
Supervisor |
2 |
Editor |
3 |
Author |
4 |
Contributor |
5 |
VIP Member |
6 |
General Member |
Menu Positions
| Position | Sidebar Location | Top Navbar Location |
|---|---|---|
main |
Below "Main Navigation" label | After Dashboard link |
management |
Below "Management" label | As a separate nav item or dropdown |
settings |
Below management items | As a "Settings" dropdown |
external |
Below "External" label | Inside the "External" dropdown |
⚙️ Public API Reference
AdminMenu::add(array $item)
Registers a new navigation item into the menu registry.
AdminMenu::add([
'id' => 'my_module',
'label' => _('My Module'),
'icon' => 'bi bi-box-seam',
'url' => 'index.php?page=mods&mod=my_module',
'access' => 3,
'position' => 'external',
'order' => 10,
]);
AdminMenu::addChild(string $parentId, array $child)
Injects a single sub-menu item into an existing parent menu identified by its id.
| Parameter | Type | Required | Description |
|---|---|---|---|
$parentId |
string |
✅ | The ID of the parent (e.g. 'posts'). |
$child |
array |
✅ | Sub-item definition: ['label', 'url', 'icon', 'access']. |
AdminMenu::addChildren(string $parentId, array $children)
Batch-injects multiple sub-menu items into an existing parent item.
AdminMenu::addChildren('posts', [
['label' => _('New Sub'), 'url' => '...'],
['label' => _('Another'), 'url' => '...']
]);
AdminMenu::remove(string $id)
Removes a previously registered menu item by its unique id.
// Remove the core Comments menu item
AdminMenu::remove('comments');
AdminMenu::getItems(?string $position)
Returns a sorted array of all registered items, optionally filtered by position.
$mainItems = AdminMenu::getItems('main');
AdminMenu::renderSidebar(?string $position)
Renders the <li> HTML for the admin sidebar navigation.
echo AdminMenu::renderSidebar('main');
echo AdminMenu::renderSidebar('external');
AdminMenu::renderTopNav(?string $position)
Renders the Bootstrap <li> items for the horizontal top navbar.
echo AdminMenu::renderTopNav('main');
echo AdminMenu::renderTopNav('settings');
🔏 Child Items Schema
The children key accepts an array of sub-items. Each child follows the same schema but does not support nested children (one level deep only).
| Key | Type | Required | Description |
|---|---|---|---|
label |
string |
✅ | Display text for the sub-item. |
url |
string |
✅ | Target URL for this sub-menu entry. |
icon |
string |
❌ | Optional icon for this child item. |
access |
int |
❌ | Override access level for this child. |
$_GET['page'] or $_GET['mod'] against the id field and url strings of each item. Always use a unique id that matches your module's page or mod query parameter.order values that are multiples of 10 (10, 20, 30...). Use odd numbers or values between core items (e.g., 15, 25) to inject items between existing entries.See Also
- How-To: Admin Menu Registration — Practical module and theme integration guide.
- Hooks Class — Using hooks for extended customization.
- Mod Class — Module lifecycle and loading order.
- User Class — Access level system reference.