block_core_navigation_parse_blocks_from_menu_items

The timeline below displays how wordpress function block_core_navigation_parse_blocks_from_menu_items has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Turns menu item data into a nested array of parsed blocks
 *
 * @deprecated 6.3.0 Use WP_Navigation_Fallback::parse_blocks_from_menu_items() instead.
 *
 * @param array $menu_items               An array of menu items that represent
 *                                        an individual level of a menu.
 * @param array $menu_items_by_parent_id  An array keyed by the id of the
 *                                        parent menu where each element is an
 *                                        array of menu items that belong to
 *                                        that parent.
 * @return array An array of parsed block data.
 */
function block_core_navigation_parse_blocks_from_menu_items($menu_items, $menu_items_by_parent_id)
{
    _deprecated_function(__FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::parse_blocks_from_menu_items');
    if (empty($menu_items)) {
        return array();
    }
    $blocks = array();
    foreach ($menu_items as $menu_item) {
        $class_name = (!empty($menu_item->classes)) ? implode(' ', (array) $menu_item->classes) : null;
        $id = (null !== $menu_item->object_id && 'custom' !== $menu_item->object) ? $menu_item->object_id : null;
        $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target;
        $rel = (null !== $menu_item->xfn && '' !== $menu_item->xfn) ? $menu_item->xfn : null;
        $kind = (null !== $menu_item->type) ? str_replace('_', '-', $menu_item->type) : 'custom';
        $block = array('blockName' => isset($menu_items_by_parent_id[$menu_item->ID]) ? 'core/navigation-submenu' : 'core/navigation-link', 'attrs' => array('className' => $class_name, 'description' => $menu_item->description, 'id' => $id, 'kind' => $kind, 'label' => $menu_item->title, 'opensInNewTab' => $opens_in_new_tab, 'rel' => $rel, 'title' => $menu_item->attr_title, 'type' => $menu_item->object, 'url' => $menu_item->url));
        $block['innerBlocks'] = isset($menu_items_by_parent_id[$menu_item->ID]) ? block_core_navigation_parse_blocks_from_menu_items($menu_items_by_parent_id[$menu_item->ID], $menu_items_by_parent_id) : array();
        $block['innerContent'] = array_map('serialize_block', $block['innerBlocks']);
        $blocks[] = $block;
    }
    return $blocks;
}

WordPress Version: 5.9

/**
 * Turns menu item data into a nested array of parsed blocks
 *
 * @param array $menu_items               An array of menu items that represent
 *                                        an individual level of a menu.
 * @param array $menu_items_by_parent_id  An array keyed by the id of the
 *                                        parent menu where each element is an
 *                                        array of menu items that belong to
 *                                        that parent.
 * @return array An array of parsed block data.
 */
function block_core_navigation_parse_blocks_from_menu_items($menu_items, $menu_items_by_parent_id)
{
    if (empty($menu_items)) {
        return array();
    }
    $blocks = array();
    foreach ($menu_items as $menu_item) {
        $class_name = (!empty($menu_item->classes)) ? implode(' ', (array) $menu_item->classes) : null;
        $id = (null !== $menu_item->object_id && 'custom' !== $menu_item->object) ? $menu_item->object_id : null;
        $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target;
        $rel = (null !== $menu_item->xfn && '' !== $menu_item->xfn) ? $menu_item->xfn : null;
        $kind = (null !== $menu_item->type) ? str_replace('_', '-', $menu_item->type) : 'custom';
        $block = array('blockName' => isset($menu_items_by_parent_id[$menu_item->ID]) ? 'core/navigation-submenu' : 'core/navigation-link', 'attrs' => array('className' => $class_name, 'description' => $menu_item->description, 'id' => $id, 'kind' => $kind, 'label' => $menu_item->title, 'opensInNewTab' => $opens_in_new_tab, 'rel' => $rel, 'title' => $menu_item->attr_title, 'type' => $menu_item->object, 'url' => $menu_item->url));
        $block['innerBlocks'] = isset($menu_items_by_parent_id[$menu_item->ID]) ? block_core_navigation_parse_blocks_from_menu_items($menu_items_by_parent_id[$menu_item->ID], $menu_items_by_parent_id) : array();
        $block['innerContent'] = array_map('serialize_block', $block['innerBlocks']);
        $blocks[] = $block;
    }
    return $blocks;
}