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

Jennifer Hodgdon yahgrp at poplarware.com
Tue Nov 20 17:15:50 GMT 2007


add_action( 'admin_menu' ) or remove_action( 'admin_menu') has to run 
before the admin menu is displayed on the screen for it to have any 
effect. So you probably need to do your POST variable processing 
pretty early during WordPress startup for it to work as desired.

Hope that helps / makes sense,
     Jennifer


Robert R. Marsh, SJ wrote:
> 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.

-- 
Jennifer Hodgdon

Poplar ProductivityWare * www.poplarware.com
Web Databases/Scripts * Modeling/Analysis/Palm OS Software



More information about the wp-hackers mailing list