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

Computer Guru computerguru at neosmart.net
Wed Nov 21 05:39:56 GMT 2007


Add some code to the *second* menu that checks if it's supposed to be
disabled. If it is, redirect users to the first.

On 11/20/07, Robert R. Marsh, SJ <rmarshsj at hotmail.com> 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
>



-- 
Computer Guru
Director,
NeoSmart Technologies
http://neosmart.net/blog/


More information about the wp-hackers mailing list