Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#35203 closed enhancement (fixed)

Capacity to change the type label in set nav menu items in Customize

Reported by: joe_bopper's profile joe_bopper Owned by: westonruter's profile westonruter
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.3
Component: Customize Keywords: has-patch commit
Focuses: Cc:


Currently the Customize interface outputs all non-default item type labels as "Custom Link" on first load, even though they may have been added by a different item type (using the hooks customize_nav_menu_available_items and customize_nav_menu_available_item_types). The only thing needed to fix this is to add a filter hook into the function wp_customize_nav_menu_item_setting::value_as_wp_post_nav_menu_item, I believe. It'd be best to behave similarly to the wp_setup_nav_menu_item hook.


Attachments (2)

35203.diff (786 bytes) - added by celloexpressions 8 years ago.
Introduce customize_setup_nav_menu_item filter to allow modifications to nav-menu-item as wp_post objects in the Customizer.
35203.1.diff (680 bytes) - added by celloexpressions 8 years ago.
Reuse wp_setup_nav_menu_items hook directly.

Download all attachments as: .zip

Change History (9)

8 years ago

Introduce customize_setup_nav_menu_item filter to allow modifications to nav-menu-item as wp_post objects in the Customizer.

#1 @celloexpressions
8 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.6
  • Version set to 4.3

Good idea @joe_bopper! 35203.diff introduces a customize_setup_nav_menu_item filter, which behaves the same way as wp_setup_nav_menu_item, but is named differently in case in needs to be used differently for items in the customizer. It makes the two filters for more specific properties redundant, but we probably can't remove those at this point.

For the issue mentioned in the ticket description, this can now be used as:

add_filter( 'customize_setup_nav_men_item', function( $menu_item ) {
     if ( conditional ) {
          $menu_item->type_label = __( 'Something Else' );
     return $menu_item;

@westonruter, are you okay with the naming of this? It's derived from this function's derivation from wp_setup_nav_menu_item().

#2 @westonruter
8 years ago

@celloexpressions there is already a wp_setup_nav_menu_item filter that applies in wp_setup_nav_menu_item(). This actually will be getting called in WP_Customize_Nav_Menu_Item_Setting::value() if the initial value is not passed in up front (to save on performance). So I think what is needed is just to apply wp_setup_nav_menu_item filters at the end of WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item(). This should result in the proper type_label appearing on the nav menus admin page as well.

#3 @celloexpressions
8 years ago

We could use the same filter, but I think there may be some instances where you'd need different handling here. Can't think of a specific example right now though, so I'd be fine with reusing wp_setup_nav_menu_item directly.

Would just switch wp for customize in the patch.

8 years ago

Reuse wp_setup_nav_menu_items hook directly.

#4 @celloexpressions
8 years ago

  • Keywords commit added
  • Owner set to westonruter
  • Status changed from new to reviewing

@westonruter this should be ready to commit with the addition of the wp_setup_nav_menu_item hook in the customizer.

#5 @westonruter
8 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 37405:

Customize: Ensure that wp_setup_nav_menu_item filter applies consistently on nav_menu_item setting values.

The filter was being applied in WP_Customize_Nav_Menu_Item_Setting::value() but not in WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item().

Props celloexpressions, westonruter.
Fixes #35203.

#6 @celloexpressions
8 years ago

  • Keywords needs-dev-note added

#7 @ocean90
8 years ago

  • Keywords needs-dev-note removed
Note: See TracTickets for help on using tickets.