I’m the author of the Nav Menu Roles plugin that lets you display/hide menu items based on the user’s role. It has come to my attention that the menu item meta does not import when using the regular WordPress plugin/tool for importing.
Each menu item is essentially just a post in the database, and I’ve been saving the data as post meta. It appears in the exported XML. Here’s a sample from a test export I just did locally.
<item>
<title>Art & Design</title>
<link>http://localhost/blog/2013/01/13/263/</link>
<pubDate>Mon, 14 Jan 2013 03:36:16 +0000</pubDate>
<dc:creator>helga</dc:creator>
<guid isPermaLink="false">http://localhost/blog/2013/01/13/263/</guid>
<description></description>
<content:encoded><![CDATA[]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>263</wp:post_id>
<wp:post_date>2013-01-13 22:36:16</wp:post_date>
<wp:post_date_gmt>2013-01-14 03:36:16</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>263</wp:post_name>
<wp:status>publish</wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>1</wp:menu_order>
<wp:post_type>nav_menu_item</wp:post_type>
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="nav_menu" nicename="main-menu"><![CDATA[Main Menu]]></category>
<wp:postmeta>
<wp:meta_key>_menu_item_type</wp:meta_key>
<wp:meta_value><![CDATA[taxonomy]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_menu_item_menu_item_parent</wp:meta_key>
<wp:meta_value><![CDATA[0]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_menu_item_object_id</wp:meta_key>
<wp:meta_value><![CDATA[6]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_menu_item_object</wp:meta_key>
<wp:meta_value><![CDATA[category]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_menu_item_target</wp:meta_key>
<wp:meta_value><![CDATA[]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_menu_item_classes</wp:meta_key>
<wp:meta_value><![CDATA[a:1:{i:0;s:6:"design";}]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_menu_item_xfn</wp:meta_key>
<wp:meta_value><![CDATA[]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_menu_item_url</wp:meta_key>
<wp:meta_value><![CDATA[]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_nav_menu_role</wp:meta_key>
<wp:meta_value><![CDATA[a:2:{i:0;s:13:"administrator";i:1;s:12:"shop_manager";}]]></wp:meta_value>
</wp:postmeta>
</item>
But then on import, the meta key _nav_menu_role
doesn’t even appear in the database. I’m running a multisite locally, but the user who brought this issue to my attention is not. I’d like to fix this issue for everyone who uses this plugin, but I am so stumped about where to even begin looking. I thought it might be a problem with serialization/non-serialization, but the key isn’t corrupt, it isn’t even there after the import.
UPDATE: I’ve investigated the importer plugin and for menu items, the plugin only imports the traditional, pre-defined meta.. such as ‘class’.
The problem was ultimately with the WordPress Importer plugin. I could hack at it (and have suggested an improvement to the developers) but I am going to got around this by writing a custom Importer of my own. It isn’t the most convenient (to re-upload the .XML file) but in cases where users have complex menus it is better than losing the meta values.
It needs more testing, but I should be adding it to my plugin in the next version.
Custom Importer for Menu Item Meta
The problem was ultimately with the WordPress Importer plugin. I could hack at it (and have suggested an improvement to the developers) but I am going to got around this by writing a custom Importer of my own. It isn’t the most convenient (to re-upload the .XML file) but in cases where users have complex menus it is better than losing the meta values.
It needs more testing, but I should be adding it to my plugin in the next version.
Custom Importer for Menu Item Meta