Priority
All hooks & filters have a priority. Those are used to order the functions that are attached to hooks. By default the priority is 10
.
As the default is 10, there’s a big chance that your filter/action gets hooked too early and therefore can’t affect the actual output.
Edit:
- Imagine that the plugin hooks it’s bootstrap into the
'admin_init'
hook to add something that needs permissions to access. Inside that bootstrap it hooks something to the (fictional)'fantastic_hook'
. - Imagine that you hook some extension of a plugin to the
'after_theme_setup'
hook. There you add some function to the (fictional)'fantastic_hook'
too.
So the result of print_r( $GLOBALS['wp_filter']['fantastic_hook'] );
would be the following:
[10] Array => ['fantastic_hook']
(
Array => ['your_custom_extension']
Array => ['the_plugin_bootstrap']
)
As your extension and the bootstrap run both at priority 10
. But yours got added first and will therefore run first. And there comes the problem…
About the menu items
The admin menu works pretty similar: You have a priority (the (sub-)array index) that cares about ordering and placing the menu items.
// Example for your functions.php:
function dump_filters()
{
$output="";
foreach ( array( $GLOBALS['menu'], $GLOBALS['submenu'] ) as $item )
$output .= var_export( $item, false );
echo "<pre>{$output}</pre>";
}
add_action( 'adminmenu', 'dump_filters', 999 );
Note: I wrote a pretty intense post about the menu order, where you can see how you’d reorder the menu and read a little bit about the behind-the-scenes of the menu and it’s limitations.