Admin config screen without menu

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 the admin_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

current_user_can( ... );
wp_die( __('You do not have sufficient permissions to access this page.') );

might be a helpful additional hint.

Leave a Comment