One last quick note: this should not be used before the menu is set. 'admin_init' is a safe bet for the earliest time to use this. I also added some code to leave gracefully if the menus aren’t set.
Sweet! and here I thought I was the only crazy person who wanted to do something like this!
Well, based on what I think you’re wanting (something similar to what I posted here), then here’s the solution I came up with (taking advantage of the function given above)
Originally I thought I was going to have to check to see which of my plugins were active each time a new plugin was activated.
I had figured I’d use is_plugin_active() to see which menu items to display beneath the parent “main” menu item… However, this turned out to be harder than I thought because that function isn’t activated yet when the plugin accesses the file that all this would be in.
Thankfully, it wound up being so simple it was staring me in the face the whole time… Each plugin that’s activated can simply add that plugin’s submenu to the parent menu without having to worry about checking for the existence of other active plugins…
I added this to each of “My” plugins (aka, the plugins my company released)
Just modify that for each of the plugins you wish to add under one menu item, and insert the plugin appropriate modified version in each of the relevant plugins.
Something like this should work.
$handle
should be the menu’s slug; set$sub
to true to search submenus (defaults to top level menus):One last quick note: this should not be used before the menu is set.
'admin_init'
is a safe bet for the earliest time to use this. I also added some code to leave gracefully if the menus aren’t set.Here is a simpler way of doing it:
Sweet! and here I thought I was the only crazy person who wanted to do something like this!
Well, based on what I think you’re wanting (something similar to what I posted here), then here’s the solution I came up with (taking advantage of the function given above)
Originally I thought I was going to have to check to see which of my plugins were active each time a new plugin was activated.
I had figured I’d use
is_plugin_active()
to see which menu items to display beneath the parent “main” menu item… However, this turned out to be harder than I thought because that function isn’t activated yet when the plugin accesses the file that all this would be in.Thankfully, it wound up being so simple it was staring me in the face the whole time… Each plugin that’s activated can simply add that plugin’s submenu to the parent menu without having to worry about checking for the existence of other active plugins…
I added this to each of “My” plugins (aka, the plugins my company released)
Then I added this little snippet to each of the plugins:
Just modify that for each of the plugins you wish to add under one menu item, and insert the plugin appropriate modified version in each of the relevant plugins.
Here’s a nice terse way of doing it without all those conditionals and foreach loops.