How to create sub menu with a URL parameter?

I would like to add parameter for the submenus, but when I click to the admin page I receive the following message:

You do not have sufficient permissions to access this page.

Code:

add_submenu_page(  
'sandbox',                  
'Sandbox Options',          
'Options',                  
'administrator',            
'sandbox_options&tab=4',    
'sandbox_options_display'
); 

Without &tab=4 everything is okay.

3 Answers
3

You’d have to manipulate the global $submenu and modify the link in it. Or use jQuery.

The following example adds a submenu in the Dashboard menu and changes the destination link just after. The submenu page will dump the contents of the global var.

add_action( 'admin_menu', function()
{
    add_submenu_page(  
        'index.php',                  
        'Sandbox Options',          
        'Options',                  
        'administrator',            
        'sandbox_options',    
        function() { global $submenu; var_dump($submenu); }
    );
    global $submenu; 
    $submenu['index.php'][11][2] = 'index.php?page=sandbox_options&tab=3';
});

[Update]

The example given, Redux Framework, uses the following technique:

  • Add a menu page with a slug example_slug.

  • Add the submenu pages and use the same slug example_slug + &tab=N.

  • All the menu and submenu pages are rendered with the menu callback. The submenu have null callbacks.

Example:

add_submenu_page(  
    'sandbox',                  
    'Sandbox Options',          
    'Options',                  
    'add_users',            
    'sandbox&tab=4',    
    '__return_null'
); 

Leave a Comment