[SOLVED] Question about admin navigation main

I am developing a plugin that allows to organize the Admin Navigation Main entries by sections.

My problem is that the filterAdminNavigationMain function just returns the pre-installation entries, so it ignores all plugin entries that have been installed later.

For example, if the admin navigation menu has these entries at the time of installing my plugin:
-> Dashboard
-> Item
-> Collection
-> Item Types
-> Tags
-> My plugin

Using filterAdminNavigationMain I get the entire navigation list. BUT if I install a new plugin …

-> Dashboard
-> Item
-> Collection
-> Item Types
-> Tags
-> My plugin
-> New Plugin

Using filterAdminNavigationMain I only get the old navigation list, without the ‘New Plugin’ entry.

Any way to get the full navigation list?

Thank you in advance.

1 Like

The reason you’re having this issue is that admin_navigation_main is the same filter the other plugins are using to add their nav entries. So, the order your filter runs in, whether it’s before or after other plugins, determines which nav entries you “see” in the filter function.

Filters have a “priority” setting which determines which run first and which run later. By default, all filters are added with a priority of 10, which means they run in an order determined by the activation/installation order of the plugin (or really, they run in a technically non-determined order).

You can set a higher number for the priority of your filter to make sure it runs later. To do this, you’ll need to use the add_filter helper instead of the “automatic” filter support from the AbstractPlugin class.

To do this you’d take admin_navigation_main out of the $_filters array and then add the following method:

public function setUp()
{
    parent::setUp();
    add_filter('admin_navigation_main', array($this, 'filterAdminNavigationMain'), 1000); 
}
1 Like

That did the trick!

Thank you very much for the detailed explanation, I’m sure others like me will appreciate it too!

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.