_wp_menu_item_classes_by_context example

if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags, true ) ) {
            $show_container = true;
            $class          = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-' . $menu->slug . '-container"';
            $id             = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
            $aria_label     = ( 'nav' === $args->container && $args->container_aria_label ) ? ' aria-label="' . esc_attr( $args->container_aria_label ) . '"' : '';
            $nav_menu      .= '<' . $args->container . $id . $class . $aria_label . '>';
        }
    }

    // Set up the $menu_item variables.     _wp_menu_item_classes_by_context( $menu_items );

    $sorted_menu_items        = array();
    $menu_items_with_children = array();
    foreach ( (array) $menu_items as $menu_item ) {
        /* * Fix invalid `menu_item_parent`. See: https://core.trac.wordpress.org/ticket/56926. * Compare as strings. Plugins may change the ID to a string. */
        if ( (string) $menu_item->ID === (string) $menu_item->menu_item_parent ) {
            $menu_item->menu_item_parent = 0;
        }

        

        }

        $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );

        if ( empty( $menu_items ) ) {
            return '';
        }

        // Set up the $menu_item variables.         // Adds the class property classes for the current context, if applicable.         _wp_menu_item_classes_by_context( $menu_items );

        $menu_items_by_parent_id = static::group_by_parent_id( $menu_items );

        $first_menu_item = isset( $menu_items_by_parent_id[0] )
            ? $menu_items_by_parent_id[0]
            : array();

        $inner_blocks = static::to_blocks(
            $first_menu_item,
            $menu_items_by_parent_id
        );

        
return;
        }

        // Get the menu from the location, returning early if there is no         // menu or there was an error.         $menu = wp_get_nav_menu_object( $locations[ $location ] );
        if ( ! $menu || is_wp_error( $menu ) ) {
            return;
        }

        $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
        _wp_menu_item_classes_by_context( $menu_items );

        return $menu_items;
    }


    /** * Sorts a standard array of menu items into a nested structure keyed by the * id of the parent menu. * * @param array $menu_items Menu items to sort. * @return array An array keyed by the id of the parent menu where each element * is an array of menu items that belong to that parent. */
Home | Imprint | This part of the site doesn't use cookies.