library/Walker/SidebarMenu.php
public function getChildOf($current_page, $elements)
    {
        $child_of = 0;

        if (is_a($current_page, '\WP_Post')) {
            $current_page = $current_page->ID;
        }

        foreach ($elements as $key => $element) {
            if (isset($element->ID) && isset($current_page) && $element->ID == $current_page) {
                $child_of = $element->ID;
                unset($elements[$key]);

                if (intval($element->menu_item_parent) > 0) {
                    $child_of = $this->getChildOf(intval($element->menu_item_parent), $elements);
                }

                break;
            }
        }

        return $child_of;
    }
public function getChildOf($current_page, $elements)
    {
        $child_of = 0;

        if (is_a($current_page, '\WP_Post')) {
            $current_page = $current_page->ID;
        }

        foreach ($elements as $key => $element) {
            if (isset($element->ID) && isset($current_page) && $element->ID == $current_page) {
                $child_of = $element->ID;
                unset($elements[$key]);

                if (intval($element->menu_item_parent) > 0) {
                    $child_of = $this->getChildOf(intval($element->menu_item_parent), $elements);
                }

                break;
            }
        }

        return $child_of;
    }
public function getChildOf ( $ current_page , $ elements ) { $ child_of = 0 ; if ( is_a ( $ current_page , '\WP_Post' ) ) { $ current_page = $ current_page -> ID ; } foreach ( $ elements as $ key => $ element ) { if ( isset ( $ element -> ID ) && isset ( $ current_page ) && $ element -> ID == $ current_page ) { $ child_of = $ element -> ID ; unset ( $ elements [ $ key ] ) ; if ( intval ( $ element -> menu_item_parent ) > 0 ) { $ child_of = $ this -> getChildOf ( intval ( $ element -> menu_item_parent ) , $ elements ) ; } break ; } } return $ child_of ; }
Find which the top parent for the current page
@param  integer $current_page Current page menu id
@param  array $elements       Menu elements
@return integer               Menu parent id (child_of)
Find which the top parent for the current page