Kevin
Kevin

Reputation: 2688

Wordpress Menu Issue

Can someone help me with my Wordpress menu for a custom plugin I'm creating?

        // Add the menu, only for administrators            
        public function add_menu(){
            if(is_admin()){
                add_menu_page(__('EM Collaboration Main Page', 'em-collaboration'), 
                                  __('EM Collaboration', 'em-collaboration'), 
                                  'manage_options', 
                                  'em-collaboration/em-main.php', 
                                  '', '', 21);
                add_submenu_page('em-collaboration/em-main.php', 
                                      __('EM Collaboration Main Page', 'em-collaboration'), 
                                      __('All Collab Groups', 'em-collaboration'), 
                                      'manage_options', 
                                      'em-collaboration/em-main.php');
            }
        }

The sub-menu is not showing for some reason, and I am really unsure as to why that is... I've looked through the codex and from what I can see it should be showing...

UPDATE

        // Add the menu, only for administrators            
        public function add_menu(){
            if(is_admin()){
                add_menu_page(__('EM Collaboration All Groups', 'em-collaboration'), 
                                  __('EM Collaboration', 'em-collaboration'), 
                                  'manage_options',
                                  'em-collab-top', 
                                  'em-collaboration/em-main.php', 
                                  '', 
                                  21);
                add_submenu_page('em-collab-top', 
                                      __('EM Collaboration Settings', 'em-collaboration'), 
                                      __('Settings', 'em-collaboration'), 
                                      'manage_options', 
                                      'em-collaboration/em-settings.php');
            }
        }

Upvotes: 0

Views: 79

Answers (1)

Thulur
Thulur

Reputation: 358

The problem is the menu_slug. It is the parameter behind 'manage_options'. You chose 'em-collaboration/em-main.php' for the menu and the submenu. The reference says, if both are the same the menu point won't be duplicated.

add_submenu_page

So your code has to look same like:

public function add_menu(){
        if(is_admin()){
            add_menu_page(__('EM Collaboration Main Page', 'em-collaboration'), 
                              __('EM Collaboration', 'em-collaboration'), 
                              'manage_options', 
                              '<the_menu_slug>', 
                              '', '', 21);
            add_submenu_page('em-collaboration/em-main.php', 
                                  __('EM Collaboration Main Page', 'em-collaboration'), 
                                  __('All Collab Groups', 'em-collaboration'), 
                                  'manage_options', 
                                  '<the_submenu_slug>');
        }
    }

"the_menu_slug" and "the_submenu_slug" need to differ to show a submenu. This slugs don't need to be a name of the file. It is just an alias name for the menu entry.

Upvotes: 1

Related Questions