wp_ajax_add_menu_item() closed to user-created menu item types

Description

I'm building a new Menus meta box, that can add a new type of menu item, lets call it 'foobar'.

The conditional inside wp_ajax_add_menu_item() is slightly off. It checks that the menu item type is not 'custom', then proceeds to assume that it's either post-type or taxonomy so it can do some DB look-ups and create an $_object variable which is then used. This means it's closed to other types of menu items.

I've chosen 'foobar', so I can distinguish those items later on when walking through the front-end output.

Change History (15)

I have a plugin (​http://wordpress.org/plugins/sf-archiver/) that builds a custom type, like @GaryJ. So far I couldn't find a way to avoid 2 php notices because of that problem (the variable $_object is not set).
Another way would be to add a filter in the switch, in a default: statement. Perhaps something like that:

If you use custom menu-item-type's to extend the menu you will see errors like this when you try to add your custom item to the nav menu in /wp-admin/nav-menus.php:

Notice: Undefined variable: _object in /srv/www/basetemplate/htdocs/wp-admin/includes/ajax-actions.php on line 1091
Notice: Trying to get property of non-object in /srv/www/basetemplate/htdocs/wp-admin/includes/ajax-actions.php on line 1095

Note: This is only shown while developing with define( 'WP_DEBUG', true );

Disabling JavaScript and attempting to add the custom item adds it with (Pending) and then you can save the menu without any issues so it seems like this is an ajax only issue.

It looks like the one line .diff submitted with this ticket would solve the problem.