$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 ) { // phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified elsewhere. if ( empty( $_POST['menu-item-acf'] ) ) { return; } $posted_values = acf_sanitize_request_args( $_POST['menu-item-acf'] ); foreach ( $posted_values as $post_id => $values ) { acf_save_post( $post_id, $values ); } // phpcs:enable WordPress.Security.NonceVerification.Missing } /** * 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; } /** * Called when WP renders a menu edit form. * Used to set global data and customize the Walker class. * * @date 26/5/17 * @since 5.6.0 * * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. * @param int $menu_id ID of the menu being rendered. * @return string */ 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 ); // Return class. return $class; } /* * 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() { // phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified elsewhere. if ( empty( $_POST['menu-item-acf'] ) ) { return; } $posted_values = acf_sanitize_request_args( $_POST['menu-item-acf'] ); foreach ( $posted_values as $post_id => $values ) { // vars $prefix = 'menu-item-acf[' . $post_id . ']'; // validate acf_validate_values( $values, $prefix ); } // phpcs:enable // phpcs:disable WordPress.Security.NonceVerification.Missing } /* * 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 = 'term_' . $nav_menu_id; // get field groups $field_groups = acf_get_field_groups( array( 'nav_menu' => $nav_menu_id, ) ); ?>