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

Callum Macdonald lists.automattic.com at callum-macdonald.com
Wed Nov 21 04:34:44 GMT 2007


How are your options being updated? By your own code, or by options.php? 
If it's by options.php then your browser is redirected back to the 
options page and the options are saved simultaneously. So you might 
arrive back before the options have updated.

Otherwise, you could hook your update_options() code into the action 
'init' so it runs ahead of everything else. Then by the time the rest of 
your plugin code runs, your options should have updated already.

Cheers - Callum.

Robert R. Marsh, SJ wrote:
> 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
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
>   



More information about the wp-hackers mailing list