Make WordPress Core

Opened 12 years ago

Closed 11 years ago

#21898 closed enhancement (duplicate)

Custom Fields for Menu Items

Reported by: helgatheviking's profile helgatheviking Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-patch
Focuses: Cc:


I think plugin authors should be able to able to add custom fields to menu items. I'd like to set certain menu items as viewable only by certain roles. Currently this is possible, but only by duplicating the entire Walker_Nav_Menu_Edit walker. It'd be much easier if there was a hook inside the Walker instead.

For instance, in /wp-admin/includes/nav-menu.php

directly following:

<p class="field-description description description-wide">
	<label for="edit-menu-item-description-<?php echo $item_id; ?>">
		<?php _e( 'Description' ); ?><br />
		<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
		<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>

You could easily place:

<?php do_action( 'wp_nav_menu_custom_fields', $item, $depth, $args ); ?>

Since there are already hooks for wp_update_nav_menu_item and wp_setup_nav_menu_item it is already possible to save the save and to call it back when using it in the front-end Walker.

Attachments (1)

wp_nav_menu_custom_fields.patch (645 bytes) - added by mordauk 12 years ago.
Adds hook.

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
12 years ago

  • Component changed from General to Menus
  • Version trunk deleted

#2 @mordauk
12 years ago

  • Cc pippin@… added

12 years ago

Adds hook.

#3 @mindctrl
12 years ago

  • Cc mindctrl added

#4 @greenshady
12 years ago

  • Cc justin@… added

#5 @Chouby
11 years ago

  • Cc frederic.demarle@… added

+1 for this hook. As mentionned above, we can derive a class from Walker_Nav_Menu_Edit and copy paste the whole start_el function. But that's a lot of duplicate code. As always in these cases, it is hard to maintain if the core code evolves. And what happens if two plugins do the same?

#6 @Chouby
11 years ago

  • Keywords has-patch added

Since there is already a patch proposed

#7 @SergeyBiryukov
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #18584.

Note: See TracTickets for help on using tickets.