0

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'));
1
  • You are sure on_manage_link1,on_manage_link2 are different and call different files or content?
    – Ryan Bayne
    Commented Mar 10, 2014 at 10:18

2 Answers 2

0

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) );
1
  • It is different I added code to question
    – raaaa
    Commented Mar 10, 2014 at 6:21
-1

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.

1
  • FILE is a PHP magic constant and I've never found it to be null. It should always return the file name that it is being used within. This could cause you other issues so it is worth coming back to if you do experience troubles.
    – Ryan Bayne
    Commented Mar 16, 2014 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.