color = get_post_meta( $menu_item->ID, '_menu_item_color', true ); $menu_item->icon = get_post_meta( $menu_item->ID, '_menu_item_icon', true ); return $menu_item; } // add custom menu fields to menu add_filter( 'wp_setup_nav_menu_item', 'mts_add_custom_nav_fields' ); /** * Save menu custom fields * * @access public * @since 1.0 * @return void */ function mts_update_custom_nav_fields( $menu_id, $menu_item_db_id, $args ) { // Check if element is properly sent if ( !empty($_REQUEST['menu-item-color']) && is_array( $_REQUEST['menu-item-color']) ) { $color_value = $_REQUEST['menu-item-color'][$menu_item_db_id]; update_post_meta( $menu_item_db_id, '_menu_item_color', $color_value ); } if ( !empty($_REQUEST['menu-item-icon']) && is_array( $_REQUEST['menu-item-icon']) ) { $icon_value = $_REQUEST['menu-item-icon'][$menu_item_db_id]; update_post_meta( $menu_item_db_id, '_menu_item_icon', $icon_value ); } } // save menu custom fields add_action( 'wp_update_nav_menu_item','mts_update_custom_nav_fields', 10, 3 ); /** * Define new Walker edit * * @access public * @since 1.0 * @return void */ function mts_edit_walker($walker,$menu_id) { return 'Walker_Nav_Menu_Edit_Custom'; } // edit menu walker add_filter( 'wp_edit_nav_menu_walker', 'mts_edit_walker', 10, 2 ); /** * /!\ This is a copy of Walker_Nav_Menu_Edit class in core * * Create HTML list of nav menu input items. * * @package WordPress * @since 3.0.0 * @uses Walker_Nav_Menu */ class Walker_Nav_Menu_Edit_Custom extends Walker_Nav_Menu { /** * @see Walker_Nav_Menu::start_lvl() * @since 3.0.0 * * @param string $output Passed by reference. */ function start_lvl(&$output, $depth = 0, $args = array()) { } /** * @see Walker_Nav_Menu::end_lvl() * @since 3.0.0 * * @param string $output Passed by reference. */ function end_lvl(&$output, $depth = 0, $args = array()) { } /** * @see Walker::start_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param object $args */ function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { global $_wp_nav_menu_max_depth; $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; ob_start(); $item_id = esc_attr( $item->ID ); $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce', ); $original_title = ''; if ( 'taxonomy' == $item->type ) { $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); if ( is_wp_error( $original_title ) ) $original_title = false; } elseif ( 'post_type' == $item->type ) { $original_object = get_post( $item->object_id ); $original_title = $original_object->post_title; } $classes = array( 'menu-item menu-item-depth-' . $depth, 'menu-item-' . esc_attr( $item->object ), 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'), ); $title = $item->title; if ( ! empty( $item->_invalid ) ) { $classes[] = 'menu-item-invalid'; /* translators: %s: title of menu item which is invalid */ $title = sprintf( __( '%s (Invalid)','wpneon' ), $item->title ); } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) { $classes[] = 'pending'; /* translators: %s: title of menu item in draft status */ $title = sprintf( __('%s (Pending)','wpneon'), $item->title ); } $title = empty( $item->label ) ? $title : $item->label; ?>