Background to my question:
I have the following in my code
add_action('admin_menu', __NAMESPACE__.'\menu_item');
function menu_item() {
add_menu_page(...);
}
From the WordPress documentation it is said that 'admin_menu'
hook is called after the menu structure is in place but this doesn't seem to be the case as interrupting it results in an empty html page.
From my understanding 'admin_menu'
is called for the admin environment after all admin functionality is loaded but before rendering the page similar to 'template_redirect'
for posts. 'add_menu_page' sets up the menu with a link to admin.php?page=mypage
executing a function when navigating to admin.php?page=mypage
. By the time admin.php?page=mypage
executes the page is already rendered except for the plugin code.
What I'm looking for:
Is there a hook similar to 'admin_menu'
that gets called only with admin.php?page=mypage
but before any html is sent?
What I'm looking to do is send my own response when certain parameters are present and only when my plugin is loaded.
EDIT: Let me clarify the question some more. 'admin_menu'
loads before any html is sent but also before WordPress has determined which plugin function to load, i.e. admin.php?page=mypage
. The next hook is the plugin function set up with add_menu_page()
which is specific to the plugin but that only executes after the html is rendered.
Background to my question:
I have the following in my code
add_action('admin_menu', __NAMESPACE__.'\menu_item');
function menu_item() {
add_menu_page(...);
}
From the WordPress documentation it is said that 'admin_menu'
hook is called after the menu structure is in place but this doesn't seem to be the case as interrupting it results in an empty html page.
From my understanding 'admin_menu'
is called for the admin environment after all admin functionality is loaded but before rendering the page similar to 'template_redirect'
for posts. 'add_menu_page' sets up the menu with a link to admin.php?page=mypage
executing a function when navigating to admin.php?page=mypage
. By the time admin.php?page=mypage
executes the page is already rendered except for the plugin code.
What I'm looking for:
Is there a hook similar to 'admin_menu'
that gets called only with admin.php?page=mypage
but before any html is sent?
What I'm looking to do is send my own response when certain parameters are present and only when my plugin is loaded.
EDIT: Let me clarify the question some more. 'admin_menu'
loads before any html is sent but also before WordPress has determined which plugin function to load, i.e. admin.php?page=mypage
. The next hook is the plugin function set up with add_menu_page()
which is specific to the plugin but that only executes after the html is rendered.
1 Answer
Reset to default 0admin_init
runs before the page is rendered, does that help?
'admin_menu'
hook is called before that but is not specific to the plugin. The hook set up withadd_menu_page()
is specific to the plugin but by that time the html is in place. There's a missing hook specific to the plugin but before the html is in place. – PromZA Commented 2 days ago