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

Callum Macdonald lists.automattic.com at callum-macdonald.com
Thu Nov 22 02:37:02 GMT 2007


Using priorities probably would have required 2 actions to be added. One 
early and one late. Anyway, glad you got it sorted, I'd also be curious 
to see your code. Cheers - Callum.

Robert R. Marsh, SJ wrote:
> Callum and Jennifer,
>
> I got it to work by hooking into the 'init' action. It took a little playing
> around with action priorities too. Until I boosted the priority I could
> remove the extra menu but not add it. Anyway it's working now.
>
> Thanks, 
> Rob
> http://rmarsh.com
>
>   
>> Date: Tue, 20 Nov 2007 23:34:44 -0500
>> From: Callum Macdonald <lists.automattic.com at callum-macdonald.com>
>> Subject: Re: [wp-hackers] updating plugin admin menus on the fly
>> To: wp-hackers at lists.automattic.com
>> Message-ID: <4743B564.3050204 at callum-macdonald.com>
>> Content-Type: text/plain; charset=us-ascii; format=flowed
>>
>> 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