Admin menu links just refresh the page

I'm using add_submenu_page() function to add some options to my plugin. On Linux hosting everything works like it should, on Windows hosting those 5 sub-menus have same link somehow and when I click on them page just reloads. What can be issue? Both hosts are using same PHP version. Here is the code

$this-page_hooks['link1'] = add_submenu_page(__FILE__, __('link1', 'domain'), __('link1', 'domain'), $acl_table['manage_link1'], 'wp-plugin-link1', array($this, 'on_manage_link1'));
$this-page_hooks['link2'] = add_submenu_page(__FILE__, __('link2', 'domain'), __('link2', 'domain'), $acl_table['manage_link2'], 'wp-plugin-link2', array($this, 'on_manage_link2'));
$this-page_hooks['link3'] = add_submenu_page(__FILE__, __('link3', 'domain'), __('link3', 'domain'), $acl_table['manage_link3'], 'wp-plugin-link3', array($this, 'on_manage_link3'));
$this-page_hooks['link4'] = add_submenu_page(__FILE__, __('link4', 'domain'), __('link4', 'domain'), 'manage_options', 'wp-plugin-link4', array($this, 'on_link4'));
$this-page_hooks['link5'] = add_submenu_page(__FILE__, __('link5', 'domain'), __('link5', 'domain'), 'manage_options', 'wp-plugin-link5', array($this, 'on_link5'));

Topic admin-menu Wordpress

Category Web


I managed to find fix. The issue was with __FILE__, windows wasn't see it as variable it was plain NULL. I changed that to parent slug and everything is running ok now.


Sounds to me like the hooked function that calls the page file itself is the same for all five uses of add_submenu_page(). Hard to tell without the code.

<?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); ?>

The $function variable should be different for all five uses meaning you need another four function or class methods. You must have one already, just duplicate it and point the include to other page files or change the functions content if your not including files.

Wordpress Codex: add_submenu_page()

Update Have you tried without using $this->page_hooks['link5'] and simplifying things further? I don't ever remember using add_submenu_page() like that. I do use it within a loop though as my menu structure/data is in an array in my plugins...

add_submenu_page($n, $c2p_mpt_arr[$k]['title'], $c2p_mpt_arr[$k]['menu'], $required_capability, $c2p_mpt_arr[$k]['slug'],  array($this,'page_' . $k) );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.