Loader That assists with adding admin bars menus to a WordPress website.
composer require underpin/loaders--admin-bar-menus
This plugin uses a built-in autoloader, so as long as it is required before Underpin, it should work as-expected.
require_once(__DIR__ . '/underpin-admin-bar-menus/underpin-admin-bar-menus.php');
- Install Underpin. See Underpin Docs
- Register new admin menus as-needed.
A very basic example could look something like this.
\Underpin\underpin()->admin_bar_menus()->add( 'menu_bar_key', [
'children' => [],
'capability' => 'administrator',
'id' => 'menu_bar_id', // Required
'args' => [ /* See WP_Admin_Bar::add_menu */ ],
'position' => 200,
'name' => 'Menu Bar',
'description' => 'A menu bar example',
] );
Alternatively, you can extend Admin_Bar_Menu
and reference the extended class directly, like so:
underpin()->admin_bar_menus()->add('menu_bar-key','Namespace\To\Class');