Admin Menu links showing link but not going to it

I have grouped some other menus from plugins to a single menu that I do not use that much to add more space to dashboard. Just that for some reason when i click on link on the new menu created it won’t go to that link, but if I hover it I can see the link as normal. This works well on chrome incognito but breaks on both firefox and chrome normal without any plugins.

class re_arange_menus {
    public function __construct() {
        //add_action('admin_menu', [$this, 'admin_menu_refresh'], 999);
        add_action('admin_init', [$this, 'admin_menu_refresh']);
        add_action('admin_head', [$this, 'add_css']);
        add_action( 'wp_before_admin_bar_render', [$this, 'mytheme_admin_bar_render'] );
    }
    public function add_css() {
        echo '<style>
            #wp-admin-bar-_options:hover {
                height: 500px;
                overflow-y: scroll;
            }
            pre {
                margin-left: 10%;
            }
          </style>';
    }
    function mytheme_admin_bar_render() {
        global $wp_admin_bar;
        $wp_admin_bar->remove_menu('_options');
    }
    function admin_menu_refresh() {
        global $submenu, $menu;
        //var_Dump($submenu);
        $menus = [
            //Easy Wp Video Options
            '_options' => 'EasyWPVideo Options',
                    //Course Notes
            'edit.php?post_type=coursenote' => 'Course Notes',
            //Mail Bank - not necesary on removing sub pages - they are integrated in UI => NNUI
            'mb_email_configuration' => 'Mail Bank',
            // SRP - NNUI
            'srp-free-settings' => 'SRP FREE',
            //BWP Panel - NNUI
            'bws_panel' => 'BWS Panel',
            //Her Slider
            'hslide' => 'Hero Slider',
            // Tools
            'tools.php' => 'Tools',
            //YOAST SEO
            'wpseo_dashboard' => 'Yoast Seo',
            // HTTPS
            'wordpress-https' => 'HTTPS',
            // Shortcodes
            'shortcodes-ultimate' => 'ShortCodes Ultimate',
            //Simple Signup Form
            'simple_signup_pro' => 'Simple Signup Pro',
            //Slides
            'edit.php?post_type=slide' => 'Slides',
            //Comments
            'edit-comments.php' => 'Comments',
            //Links
            'link-manager.php' => 'Link Manager',
            'cj-products' => 'Css Jockey'
        ];
        $parent_slug = '_options';
        add_menu_page('Rarely Used Stuff', 'Rarely Used Stuff', 'manage_options', $parent_slug, '', '', 999);
        $i = 0;
        $submenu_keys = array_keys($submenu);
        $menus_keys = array_keys($menus);
        $menus_values = array_values($menus);
        $menus_mod = [];
        $single_menu = [];
        foreach($menus as $menu_item=>$label) {
            $item_nr = array_search($menu_item, array_keys($submenu));
            if ($item_nr) {
                $menus_mod[$menu_item] = $submenu[$submenu_keys[$item_nr]];
                $first_sub_array = current($menus_mod[$menu_item]);
                //$menus_mod[$menu_item][0][] = $label;
                $first_sub_array[] = $label;
                $position = current(array_keys($menus_mod[$menu_item]));
                $menus_mod[$menu_item][$position] = $first_sub_array;
            } else {
                $single_menu[$menu_item] = $label;
            }
        }
        //var_Dump($menus_mod);
        $menus_mod = array_merge($single_menu, $menus_mod);
        //var_Dump($menus_mod);
        //var_dump($menus_mod);
        foreach($menus_mod as $remove_menu=>$submenu) {
            if(is_array($submenu)) {
                if (!empty($submenu)) {
                    foreach($submenu as $link) {
                        //var_dump($link);
                        $test = remove_submenu_page( $remove_menu, $link[2] );
                        //var_Dump($test, $remove_menu, $link[2]);
                    }
                }
            }
            $test2 = remove_menu_page($remove_menu);
        }
        foreach($menus_mod as $add_menu_url=>$add_menu_label) {
            if(is_array($add_menu_label) && !empty($add_menu_label)) {
                $isFirst = true;
                foreach($add_menu_label as $submenu_arr) {
                    $args['parent_slug'] = $parent_slug;
                    $args['page_title'] = $submenu_arr[0];
                    if(!$isFirst) {
                        $title = str_replace('&raquo;', '', '- '.$submenu_arr[0]);
                        $args['menu_title'] = $title;
                    } else {
                        $label = end($submenu_arr);
                        //var_Dump($submenu_arr);
                        $args['menu_title'] = $label;
                    }
                    $args['menu_title'] = preg_replace('#<div(.*?)>(.*?)</div>#', '', $args['menu_title']);
                    $args['capability'] = 'manage_options';
                    if(strpos($submenu_arr[2], '.php') !== false) {
                        $args['menu_slug'] = $submenu_arr[2];
                    } else {
                        $args['menu_slug'] = 'admin.php?page='.$submenu_arr[2];
                    }
                    $args['function'] = null;
                    add_submenu_page(
                        $args['parent_slug'],
                        $args['page_title'],
                        $args['menu_title'],
                        $args['capability'],
                        $args['menu_slug'],
                        $args['function']
                    );
                    $isFirst = false;
                }
            } else {
                    //var_Dump($add_menu_label);
                $args['parent_slug'] = $parent_slug;
                $args['page_title'] = $add_menu_label;
                $args['menu_title'] = $add_menu_label;
                $args['capability'] = 'manage_options';
                if(strpos($add_menu_url, '.php') !== false) {
                    $args['menu_slug'] = $add_menu_url;
                } else {
                    $args['menu_slug'] = 'admin.php?page='.$add_menu_url;
                }
                $args['function'] = null;
                add_submenu_page(
                    $args['parent_slug'],
                    $args['page_title'],
                    $args['menu_title'],
                    $args['capability'],
                    $args['menu_slug'],
                    $args['function']
                );
            }
            $i++;
        }
    }
}
new re_arange_menus;

Read more here: Admin Menu links showing link but not going to it

Leave a Reply

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