Rendering entire menu (all children) of admin menu page on admin bar not working

I am trying to show on the admin bar a custom menu created over here. The main issue is that is showing on the link to the admin menu not all of it’s children. Main code of interest looks like this:
It should show the entire array $menus in the admin bar, but instead it’s showing only rustaff page. I think add_node is not functioning correctly.

class re_arange_menus {
    public $menus = [
            '_options' => 'EasyWPVideo Options',
            'edit.php?post_type=coursenote' => 'Course Notes',
            // another 30
        ];
    public $parent_slug = 'rustaff';
    public $capabilities = 'manage_options';
    public $callback;
    public function __construct() {
        $this->callback = [$this, 'rustaff'];
        add_action('admin_menu', [$this, 'admin_menu_refresh'], 999);
        add_action('admin_bar_menu', [$this, 'toolbar_link_to_mypage'], 999);
    }
    public function toolbar_link_to_mypage($wp_admin_bar){
        global $wp_admin_bar;
        $args = [
            'id' => 'rustaff',
            'title' => 'Rarely Used Staff',
            'href' => admin_url('admin.php?page=rustaff')
        ];
        $wp_admin_bar->add_node( $args );
    }
    public function admin_menu_refresh() {
        $menus = $this->menus;
        $parent_slug = $this->parent_slug;
        $capability = $this->capabilities;
        $callback = $this->callback;
        //$callback = null;
        add_menu_page('Rarely Used Stuff', 'Rarely Used Stuff', $capability, $parent_slug, $callback, '', 999);
        foreach ($menus as $submenu=>$submenu_title) {
            add_submenu_page(
                $parent_slug,
                $submenu_title,
                $submenu_title,
                $capability,
                $submenu,
                null
            );
        }
    }
}

Read more here: Rendering entire menu (all children) of admin menu page on admin bar not working

Leave a Reply

Your email address will not be published. Required fields are marked *