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.
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);
}