[wp-hackers] updating plugin admin menus on the fly

Robert R. Marsh, SJ rmarshsj at hotmail.com
Tue Nov 20 16:55:00 GMT 2007


My question languished unanswered for a week on the support forums so I'm
taking the liberty of asking it here where the knowledgeable folk live...

I am writing two plugins, one of which is dependant on the other. Both have
option pages in the admin section. I want to show or hide the second
plugin's options page according to a setting selected on the first plugin's
options page.

That much works up to a point. I can use add_action and remove_action to add
or remove the second plugin's options page. 

	if ($_POST['show_other'] === 'true') {
		add_action('admin_menu', 'other_option_menu');
	} else {
		remove_action('admin_menu', 'other_option_menu');
	}

Unfortunately, the menu at the top of the admin screen doesn't seem to
update immediately. For example, if I choose to remove the second plugin's
option page the menu still shows a tab for it -- but if I click that tab I
get an error page.

However, if I click on another option menu tab -- or if I press the button
to update my options a second time -- the menu adjusts itself and stops
showing the second plugin's tab.

Is there any way to get the menu to sort itself out on the first update of
the options? 

Thanks,

Rob
http://rmarsh.com



More information about the wp-hackers mailing list