Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
Is this best considered best practice? If I have administration forms in my plugin, should I use this method to register scripts for form processing, or should I be using wp-admin/edit.php or wp-admin/admin.php?action=myaction –  codecowboy Jan 26 '11 at 11:26
    
@codecowboy: Please start a new question and reference this question in there. Leave a short message here as well. You will get much better feedback then. –  hakre Jan 26 '11 at 19:57
    
I started a new question here - wordpress.stackexchange.com/questions/7812/… –  codecowboy Jan 26 '11 at 20:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.