Similar to generating an array of the admin menu/submenu:
global $menu;
foreach ( $menu as $group => $item ) {
echo '<pre>'; print_r( $item ); echo '</pre>';
}
How can I get an array of all of the available menu items in the toolbar? I tried using the global $wp_admin_bar
variable, but that seems to not be the right one.
The reason why I want to generate this array is to use this in a plugin of mine to provide an option to choose which items to hide from the toolbar, allowing users to customize their settings. Right now, I manually created an array called $toolbar
to choose the items I want to hide myself:
global $wp_admin_bar;
$toolbar = array(
'wp-logo', // WordPress logo
'comments', // Comments
'new-post', // New > Post
'search' // Search
);
foreach ( $toolbar as $item ) {
$wp_admin_bar -> remove_menu( $item );
}
Update [2016-09-16]
I was able to get the entire list by using the following in my plugin settings page:
global $wp_admin_bar;
echo '<pre>'; print_r( $wp_admin_bar ); echo '</pre>';
It's too long to paste in here, so you can view the entire list on this Pastebin link. However, below is a snippet of how it starts. How can I get all of the values that are in [id] =>
and/or [parent] =>
? It looks like I would need to go through a few levels of foreach
?
WP_Admin_Bar Object (
[nodes:WP_Admin_Bar:private] => Array (
[user-actions] => stdClass Object (
[id] => user-actions
[title] =>
[parent] => my-account
[href] =>
[meta] => Array (
[class] => ab-submenu
)
[children] => Array (
[0] => stdClass Object (
[id] => user-info
[title] => Name
[parent] => user-actions
[href] => http://example.com/wp-admin/profile.php
[meta] => Array (
[tabindex] => -1
)
[children] => Array (
)
[type] => item
)
[1] => stdClass Object (
[id] => edit-profile
[title] => Edit My Profile
[parent] => user-actions
[href] => http://example.com/wp-admin/profile.php
[meta] => Array (
)
[children] => Array (
)
[type] => item
)
and so on...
admin_bar_menu
with a very low priority to be sure that every actions have been calledadmin_bar_menu
is just the hook. I'm trying to generate a list of all available toolbar menu items in my plugin settings so that that the user can check which ones to hide.