$item->type, 'nav_menu_item_id' => $item_id, 'nav_menu_item_depth' => $depth )); // render if( !empty($field_groups) ) { // open echo '
'; // loop foreach( $field_groups as $field_group ) { // load fields $fields = acf_get_fields( $field_group ); // bail if not fields if( empty($fields) ) continue; // change prefix acf_prefix_fields( $fields, $prefix ); // render acf_render_fields( $fields, $item_id, 'div', $field_group['instruction_placement'] ); } // close echo '
'; // Trigger append for newly created menu item (via AJAX) if( acf_is_ajax('add-menu-item') ): ?> update_nav_menu_items( $menu_id ); } /* * update_nav_menu_items * * description * * @type function * @date 26/5/17 * @since 5.6.0 * * @param $post_id (int) * @return $post_id (int) */ function update_nav_menu_items( $menu_id ) { // bail ealry if not set if( empty($_POST['menu-item-acf']) ) return; // loop foreach( $_POST['menu-item-acf'] as $post_id => $values ) { acf_save_post( $post_id, $values ); } } /** * wp_get_nav_menu_items * * WordPress does not provide an easy way to find the current menu being edited. * This function listens to when a menu's items are loaded and stores the menu. * Needed on nav-menus.php page for new menu with no items * * @date 23/2/18 * @since 5.6.9 * * @param type $var Description. Default. * @return type Description. */ function wp_get_nav_menu_items( $items, $menu, $args ) { acf_set_data('nav_menu_id', $menu->term_id); return $items; } /* * wp_edit_nav_menu_walker * * description * * @type function * @date 26/5/17 * @since 5.6.0 * * @param $post_id (int) * @return $post_id (int) */ function wp_edit_nav_menu_walker( $class, $menu_id = 0 ) { // update data (needed for ajax location rules to work) acf_set_data('nav_menu_id', $menu_id); // include walker if( class_exists('Walker_Nav_Menu_Edit') ) { acf_include('includes/walkers/class-acf-walker-nav-menu-edit.php'); } // return return 'ACF_Walker_Nav_Menu_Edit'; } /* * acf_validate_save_post * * This function will loop over $_POST data and validate * * @type action 'acf/validate_save_post' 5 * @date 7/09/2016 * @since 5.4.0 * * @param n/a * @return n/a */ function acf_validate_save_post() { // bail ealry if not set if( empty($_POST['menu-item-acf']) ) return; // loop foreach( $_POST['menu-item-acf'] as $post_id => $values ) { // vars $prefix = 'menu-item-acf['.$post_id.']'; // validate acf_validate_values( $values, $prefix ); } } /* * admin_footer * * This function will add some custom HTML to the footer of the edit page * * @type function * @date 11/06/2014 * @since 5.0.0 * * @param n/a * @return n/a */ function admin_footer() { // vars $nav_menu_id = acf_get_data('nav_menu_id'); $post_id = acf_get_term_post_id( 'nav_menu', $nav_menu_id ); // get field groups $field_groups = acf_get_field_groups(array( 'nav_menu' => $nav_menu_id )); ?>