I want to create a sub config from some page on admin panel, eg:
I’ve set config menu this way:
add_menu_page( 'E+', 'CRE+', 8, 'cr_e_plus_user_config', 'cr_e_plus_user_config');
add_submenu_page( 'cr_e_plus_user_config', 'E+', 'Configurations', 8, 'cr_e_plus_user_config', 'cr_e_plus_user_config');
From Configurations
page, I need to load another page when I click certain link. Now, I don’t want this new page to be listed on menu, because it will need certain parameter before I can show it.
Admin pages are basically spoken nothing else then a hook to a function, so it is technically not a problem to add your own pages without making use of the menu.
I was not aware of an API function that allows you to register own pages with ease, but there is a helper function in WordPress you can make use of:
get_plugin_page_hookname()
(undocumented function). Next to that, the hook needs to be registered in a global registry of all page hooks ($GLOBALS['_registered_pages']
) so that it’s rated valid when the page is requested.I’ve wrapped that in some sample code, just save it into your
/wp-content/mu-plugins
folder: admin_page_demo.php (WordPress MU-Plugin Example)In there you can find a function
register_admin_page()
that can register any callback you need per theadmin_menu
hook. That’s the important one, compare to Adding Administration Menus (WordPress Codex).The function returns the URL of the new admin page. You wrote that you might need to add more parameters, so I thought that might be handy.
For the demo page I hardcoded into that example, the URL is:
/wp-admin/options-general.php?page=adminpagedemo_demo_page
.Keep in mind, that you need to check for security for that page on your own because WordPress does not. Something like
might be a helpful additional hint.