[wp-hackers] how can I use the create new menu function for making a default menu

Mike Schinkel mikeschinkel at newclarity.net
Sat Jul 31 00:44:34 UTC 2010


Hi Jared:

Do you mean these found in /wp-includes/nav-menu.php?

Create Menu: 
	$menu_id = wp_create_nav_menu( $menu_name );

Create Menu Items: 
	$menu = array(
		'menu-item-object-id' => 0,
		'menu-item-object' => '',
		'menu-item-parent-id' => 0,
		'menu-item-position' => 0,
		'menu-item-type' => 'custom',
		'menu-item-title' => '',
		'menu-item-url' => '',
		'menu-item-description' => '',
		'menu-item-attr-title' => '',
		'menu-item-target' => '',
		'menu-item-classes' => '',
		'menu-item-xfn' => '',
		'menu-item-status' => '',
	);
	$menu_item_db_id = wp_update_nav_menu_item( $menu_id, 0, $menu);

Update Menu Items: 
	wp_update_nav_menu_item( $menu_id, $menu_item_db_id, $menu);

I've used them to create menus and menu items automatically.

To understand the parameters create some menus in the admin and then take a look at the values created for different types of menu items in wp_postmeta.

Hope this helps?

-Mike 

On Jul 30, 2010, at 8:25 PM, Jared Williams wrote:

> Hi,
> I know the menu system needs lots of work still, but I was wondering if
> anyone knows of a way to make use of whatever function(s) the 'Create Menu'
> does when you make a new custom named menu in the dashboard to make a
> pre-made menu to go along with a registered menu location etc. This would be
> nice so that when a theme were installed that has registered menus in it,
> the menu name you specify in the code would be created upon installing, and
> deleted when uninstalling a theme.
> 
> I've searched for some kind of solution to this, and have studied the code
> in nav-menus.php and other files with 3.0 source code. This is just about
> the only thing I am unable to figure out with 3.0, at least that I have
> tried to do so far.
> I figured here is probably the best place to ask such a question.
> 
> Thanks,
> 
> Jared Williams
> New2WP.com
> 
> 
> On Fri, Jul 30, 2010 at 11:33 AM,
> <wp-hackers-request at lists.automattic.com>wrote:
> 
>> Send wp-hackers mailing list submissions to
>>       wp-hackers at lists.automattic.com
>> 
>> To subscribe or unsubscribe via the World Wide Web, visit
>>       http://lists.automattic.com/mailman/listinfo/wp-hackers
>> or, via email, send a message with subject or body 'help' to
>>       wp-hackers-request at lists.automattic.com
>> 
>> You can reach the person managing the list at
>>       wp-hackers-owner at lists.automattic.com
>> 
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of wp-hackers digest..."
>> 
>> 
>> Today's Topics:
>> 
>>  1. Re: any way to clean after theme when it gets deleted?
>>     (Davit Barbakadze)
>>  2. Re: any way to clean after theme when it gets deleted?
>>     (Ashish Saini)
>>  3. Re: any way to clean after theme when it gets deleted?
>>     (Andrew Nacin)
>>  4. Re: any way to clean after theme when it gets deleted?
>>     (Ashish Saini)
>>  5. Re: any way to clean after theme when it gets deleted?
>>     (Davit Barbakadze)
>>  6. Re: any way to clean after theme when it gets deleted?
>>     (Andrew Nacin)
>>  7. switch_to_blog in WP3 (Bill Dennen)
>>  8. Re: any way to clean after theme when it gets deleted?
>>     (esmi at quirm dot net)
>> 
>> 
>> ----------------------------------------------------------------------
>> 
>> Message: 1
>> Date: Fri, 30 Jul 2010 17:17:51 +0400
>> From: Davit Barbakadze <jayarjo at gmail.com>
>> Subject: Re: [wp-hackers] any way to clean after theme when it gets
>>       deleted?
>> To: wp-hackers at lists.automattic.com
>> Message-ID:
>>       <AANLkTikhpSNdc-VtaLnOU2py=b+90tFjpCFLZeW+ecS6 at mail.gmail.com<b%2B90tFjpCFLZeW%2BecS6 at mail.gmail.com>
>>> 
>> Content-Type: text/plain; charset=ISO-8859-1
>> 
>> It's not about switching (activate/deactivate), but deleting. It would
>> be pretty logical to remove all the stuff that theme has created on
>> activation.
>> 
>> On Fri, Jul 30, 2010 at 3:45 PM, Ashish Saini
>> <ashishsainiashfame at gmail.com> wrote:
>>> Hi Davit,
>>> 
>>> I think a better option would be to provide uninstall function as leaving
>>> the options in the database makes sense as the user may switch back and
>> so
>>> it will save the pain of configuring it.
>>> 
>>> Thanks & Regards
>>> Ashish Saini aka Ashfame
>>> (Deserve Before You Desire)
>>> Homepage : http://www.ashfame.com | Blog : http://blog.ashfame.com |
>> Twitter
>>> : http://twitter.com/ashfame
>>> 
>>> 
>>> On Fri, Jul 30, 2010 at 4:44 PM, <diana.j.wiadji at hotmail.com> wrote:
>>> 
>>>> $
>>>> ------Original Message------
>>>> From: Davit Barbakadze
>>>> Sender: wp-hackers-bounces at lists.automattic.com
>>>> To: wp-hackers at lists.automattic.com
>>>> ReplyTo: wp-hackers at lists.automattic.com
>>>> Subject: [wp-hackers] ?any way to clean after theme when it gets
>> deleted?
>>>> Sent: Jul 30, 2010 18:02
>>>> 
>>>> I think everyone uses options and maybe even tables in their themes
>>>> nowadays. Is there any way coder can clean up after theme - delete
>>>> options, remove tables - when it get's uninstalled. Something similar
>>>> to what we have for plugins?
>>>> 
>>>> --
>>>> Davit Barbakadze
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>> 
>>>> 
>>>> 
>>>> Sent from my BlackBerry? smartphone on 3
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>> 
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>> 
>> 
>> 
>> 
>> --
>> Davit Barbakadze
>> 
>> 
>> ------------------------------
>> 
>> Message: 2
>> Date: Fri, 30 Jul 2010 18:55:18 +0530
>> From: Ashish Saini <ashishsainiashfame at gmail.com>
>> Subject: Re: [wp-hackers] any way to clean after theme when it gets
>>       deleted?
>> To: wp-hackers at lists.automattic.com
>> Message-ID:
>>       <AANLkTikU0qcxQMMVgRwTrNOEHjXoUO_o0r44C+=_96Z+ at mail.gmail.com<96Z%2B at mail.gmail.com>
>>> 
>> Content-Type: text/plain; charset=ISO-8859-1
>> 
>> You didn't get my point. I said you should provide an uninstaller function
>> that wipes out data and it shouldn't be automated upon deactivation.
>> 
>> I would hate a theme which will ask for options to be configured again when
>> I just switch back to another theme and now I want the previous theme back.
>> 
>> Thanks & Regards
>> Ashish Saini aka Ashfame
>> (Deserve Before You Desire)
>> Homepage : http://www.ashfame.com | Blog : http://blog.ashfame.com |
>> Twitter
>> : http://twitter.com/ashfame
>> 
>> 
>> On Fri, Jul 30, 2010 at 6:47 PM, Davit Barbakadze <jayarjo at gmail.com>
>> wrote:
>> 
>>> It's not about switching (activate/deactivate), but deleting. It would
>>> be pretty logical to remove all the stuff that theme has created on
>>> activation.
>>> 
>>> On Fri, Jul 30, 2010 at 3:45 PM, Ashish Saini
>>> <ashishsainiashfame at gmail.com> wrote:
>>>> Hi Davit,
>>>> 
>>>> I think a better option would be to provide uninstall function as
>> leaving
>>>> the options in the database makes sense as the user may switch back and
>>> so
>>>> it will save the pain of configuring it.
>>>> 
>>>> Thanks & Regards
>>>> Ashish Saini aka Ashfame
>>>> (Deserve Before You Desire)
>>>> Homepage : http://www.ashfame.com | Blog : http://blog.ashfame.com |
>>> Twitter
>>>> : http://twitter.com/ashfame
>>>> 
>>>> 
>>>> On Fri, Jul 30, 2010 at 4:44 PM, <diana.j.wiadji at hotmail.com> wrote:
>>>> 
>>>>> $
>>>>> ------Original Message------
>>>>> From: Davit Barbakadze
>>>>> Sender: wp-hackers-bounces at lists.automattic.com
>>>>> To: wp-hackers at lists.automattic.com
>>>>> ReplyTo: wp-hackers at lists.automattic.com
>>>>> Subject: [wp-hackers]  any way to clean after theme when it gets
>>> deleted?
>>>>> Sent: Jul 30, 2010 18:02
>>>>> 
>>>>> I think everyone uses options and maybe even tables in their themes
>>>>> nowadays. Is there any way coder can clean up after theme - delete
>>>>> options, remove tables - when it get's uninstalled. Something similar
>>>>> to what we have for plugins?
>>>>> 
>>>>> --
>>>>> Davit Barbakadze
>>>>> _______________________________________________
>>>>> wp-hackers mailing list
>>>>> wp-hackers at lists.automattic.com
>>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>> 
>>>>> 
>>>>> 
>>>>> Sent from my BlackBerry? smartphone on 3
>>>>> _______________________________________________
>>>>> wp-hackers mailing list
>>>>> wp-hackers at lists.automattic.com
>>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>> 
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>> 
>>> 
>>> 
>>> 
>>> --
>>> Davit Barbakadze
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>> 
>> 
>> 
>> ------------------------------
>> 
>> Message: 3
>> Date: Fri, 30 Jul 2010 09:45:12 -0400
>> From: Andrew Nacin <wp at andrewnacin.com>
>> Subject: Re: [wp-hackers] any way to clean after theme when it gets
>>       deleted?
>> To: wp-hackers at lists.automattic.com
>> Message-ID:
>>       <AANLkTi=ua3FWx5UJnGs9TpxYbqk_dN_GhW_bxbas01ON at mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>> 
>> On Fri, Jul 30, 2010 at 9:25 AM, Ashish Saini
>> <ashishsainiashfame at gmail.com>wrote:
>> 
>>> You didn't get my point. I said you should provide an uninstaller
>> function
>>> that wipes out data and it shouldn't be automated upon deactivation.
>>> 
>> 
>> Not sure you got his point -- I believe Davit is referring to the
>> implementation of an uninstall hook for themes. He's pretty clear he'd want
>> that triggered on deletion, not deactivation. Basically, how it works for
>> plugins.
>> 
>> I think implementing themes uninstall hooks would be a logical future step.
>> We could start by removing items created using the theme_mod functions,
>> which I don't think most themes use, but we use it for storing metadata for
>> custom backgrounds and headers.
>> 
>> 
>> ------------------------------
>> 
>> Message: 4
>> Date: Fri, 30 Jul 2010 19:48:22 +0530
>> From: Ashish Saini <ashishsainiashfame at gmail.com>
>> Subject: Re: [wp-hackers] any way to clean after theme when it gets
>>       deleted?
>> To: wp-hackers at lists.automattic.com
>> Message-ID:
>>       <AANLkTim7MQR2P6yOUa0j1TiPfWiaXDrVXfJM94Xovm-v at mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>> 
>> Andrew, I knew that. I just replied back with a possible solution for his
>> case.
>> 
>> Thanks & Regards
>> Ashish Saini aka Ashfame
>> (Deserve Before You Desire)
>> Homepage : http://www.ashfame.com | Blog : http://blog.ashfame.com |
>> Twitter
>> : http://twitter.com/ashfame
>> 
>> 
>> On Fri, Jul 30, 2010 at 7:15 PM, Andrew Nacin <wp at andrewnacin.com> wrote:
>> 
>>> On Fri, Jul 30, 2010 at 9:25 AM, Ashish Saini
>>> <ashishsainiashfame at gmail.com>wrote:
>>> 
>>>> You didn't get my point. I said you should provide an uninstaller
>>> function
>>>> that wipes out data and it shouldn't be automated upon deactivation.
>>>> 
>>> 
>>> Not sure you got his point -- I believe Davit is referring to the
>>> implementation of an uninstall hook for themes. He's pretty clear he'd
>> want
>>> that triggered on deletion, not deactivation. Basically, how it works for
>>> plugins.
>>> 
>>> I think implementing themes uninstall hooks would be a logical future
>> step.
>>> We could start by removing items created using the theme_mod functions,
>>> which I don't think most themes use, but we use it for storing metadata
>> for
>>> custom backgrounds and headers.
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>> 
>> 
>> 
>> ------------------------------
>> 
>> Message: 5
>> Date: Fri, 30 Jul 2010 18:32:12 +0400
>> From: Davit Barbakadze <jayarjo at gmail.com>
>> Subject: Re: [wp-hackers] any way to clean after theme when it gets
>>       deleted?
>> To: wp-hackers at lists.automattic.com
>> Message-ID:
>>       <AANLkTi=KdyyghUgN0-U46rkDThdGaYGmR1SH8c5F+w09 at mail.gmail.com<KdyyghUgN0-U46rkDThdGaYGmR1SH8c5F%2Bw09 at mail.gmail.com>
>>> 
>> Content-Type: text/plain; charset=ISO-8859-1
>> 
>> theme_mod functions? what do they do?
>> 
>> On Fri, Jul 30, 2010 at 5:45 PM, Andrew Nacin <wp at andrewnacin.com> wrote:
>>> On Fri, Jul 30, 2010 at 9:25 AM, Ashish Saini
>>> <ashishsainiashfame at gmail.com>wrote:
>>> 
>>>> You didn't get my point. I said you should provide an uninstaller
>> function
>>>> that wipes out data and it shouldn't be automated upon deactivation.
>>>> 
>>> 
>>> Not sure you got his point -- I believe Davit is referring to the
>>> implementation of an uninstall hook for themes. He's pretty clear he'd
>> want
>>> that triggered on deletion, not deactivation. Basically, how it works for
>>> plugins.
>>> 
>>> I think implementing themes uninstall hooks would be a logical future
>> step.
>>> We could start by removing items created using the theme_mod functions,
>>> which I don't think most themes use, but we use it for storing metadata
>> for
>>> custom backgrounds and headers.
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>> 
>> 
>> 
>> 
>> --
>> Davit Barbakadze
>> 
>> 
>> ------------------------------
>> 
>> Message: 6
>> Date: Fri, 30 Jul 2010 10:38:48 -0400
>> From: Andrew Nacin <wp at andrewnacin.com>
>> Subject: Re: [wp-hackers] any way to clean after theme when it gets
>>       deleted?
>> To: wp-hackers at lists.automattic.com
>> Message-ID:
>>       <AANLkTinDDOQTQyaZdnmazoiGn6HSGXVW9eLkffXm0HZw at mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>> 
>> On Fri, Jul 30, 2010 at 10:32 AM, Davit Barbakadze <jayarjo at gmail.com
>>> wrote:
>> 
>>> theme_mod functions? what do they do?
>> 
>> 
>> Rudimentary options storage for themes. Each theme's mods are stored in a
>> single DB option row in the form of mod_{$theme}.
>> 
>> Locations in core:
>> ./wp-includes/theme.php:1270:function get_theme_mod($name, $default =
>> false)
>> {
>> ./wp-includes/theme.php:1289:function set_theme_mod($name, $value) {
>> ./wp-includes/theme.php:1311:function remove_theme_mod( $name ) {
>> ./wp-includes/theme.php:1333:function remove_theme_mods() {
>> 
>> Codex pages:
>> http://codex.wordpress.org/Function_Reference/get_theme_mod
>> http://codex.wordpress.org/Function_Reference/set_theme_mod
>> http://codex.wordpress.org/Function_Reference/remove_theme_mod
>> http://codex.wordpress.org/Function_Reference/remove_theme_mods
>> 
>> 
>> ------------------------------
>> 
>> Message: 7
>> Date: Fri, 30 Jul 2010 11:29:11 -0400
>> From: Bill Dennen <dennen at gmail.com>
>> Subject: [wp-hackers] switch_to_blog in WP3
>> To: wp-hackers at lists.automattic.com
>> Message-ID:
>>       <AANLkTimgcjBN35jVm7+Q_9CsGcuJJdhL9E-vjWTCLfe3 at mail.gmail.com<AANLkTimgcjBN35jVm7%2BQ_9CsGcuJJdhL9E-vjWTCLfe3 at mail.gmail.com>
>>> 
>> Content-Type: text/plain; charset=ISO-8859-1
>> 
>> Hi,
>> 
>> I wrote a plugin that allows one blog to pull posts in from another
>> blog via shortcode. I call it get-news. The syntax of the shortcode is
>> something like this:
>> 
>> [get-news site_name="news" numberposts="10" show_dates="0"]
>> 
>> In short, what this code does is switch to the blog located at /news/
>> and grab the 10 most recent posts and display them on the current
>> blog. There are other options, as well - like pulling posts by
>> category or tags, showing thumbnails, etc.
>> 
>> My code uses switch_to_blog to do this. I've read that this function
>> has a heavy performance hit. But, we've been using it with WP Super
>> Cache and it has worked well for us in WPMU 2.9.2. Plus, at this
>> point, my plugin is not meant for distribution -- it's used only on
>> the site I manage. (That could change...)
>> 
>> Now, my code is broken in WP3.x. Permalinks are incorrect and
>> thumbnails do not work properly.
>> 
>> I believe it's this bug, which is now listed as a "wontfix":
>> 
>> http://core.trac.wordpress.org/ticket/12040
>> 
>> In the bug report, there is mention that this bug could be 'fixed' via
>> a plugin via the switch_blog hook.
>> 
>> I'm looking for alternate suggestions for ways to do this. At this
>> point, this bug is holding us back from going with WP3, which we'd
>> like to do for many reasons!
>> 
>> One option I toyed with initially was using RSS feeds, but I could not
>> get the thumbnails over that way.
>> 
>> Looking forward to any suggestions.
>> 
>> Thanks-
>> Bill
>> 
>> 
>> ------------------------------
>> 
>> Message: 8
>> Date: Fri, 30 Jul 2010 16:33:08 +0100
>> From: esmi at quirm dot net <esmi at quirm.net>
>> Subject: Re: [wp-hackers] any way to clean after theme when it gets
>>       deleted?
>> To: wp-hackers at lists.automattic.com
>> Message-ID: <4C52F0B4.4030908 at quirm.net>
>> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>> 
>> on 30/07/2010 15:38 Andrew Nacin said the following:
>>> On Fri, Jul 30, 2010 at 10:32 AM, Davit Barbakadze <jayarjo at gmail.com
>>> wrote:
>> 
>>>> theme_mod functions? what do they do?
>> 
>>> Rudimentary options storage for themes. Each theme's mods are stored in a
>>> single DB option row in the form of mod_{$theme}.
>> 
>> <snip>
>> 
>> It's the multiple single rows in the db that I'm not keen on. Most of
>> the time, I've been using a single row in the options table to store a
>> serialized array. Each theme then has a manual "reset" option which
>> removes all stored theme options but, thus far, I haven't found a way to
>> trigger the reset on theme deletion.
>> 
>> Mel / esmi
>> --
>> WordPress theme developer
>> http://quirm.net
>> http://blackwidows.co.uk
>> 
>> 
>> ------------------------------
>> 
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> 
>> 
>> End of wp-hackers Digest, Vol 66, Issue 120
>> *******************************************
>> 
> _______________________________________________
> 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