Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to add my new developed plugin's admin menu to an existing plugin as sub menu. Would be possible to do this?

In my first plugin I initilize the menus as follows:

function add_pages() {
    // Add a new top-level menu (ill-advised):
    add_menu_page(__('MyMenu','menu-test'), __('MyMenu','menu-test'), 'manage_options', 'menu-top-level-handle', array ($this , 'menu_toplevel_page' ) );

    // Add a second submenu to the custom top-level menu:
    add_submenu_page('menu-top-level-handle', __('Test Submenu','menu-test'), __('Test Submenu','menu-test'), 'manage_options', 'sub_page_test', array($this , 'test_sublevel_page2') );
}

The code in the second plugin:

function admin_menu () {    
    add_submenu_page( 'menu-top-level-handle', 'Lexikon', 'Lexikon', 'manage_options', 'lexikon-edit', array($this , 'lexikon_settings_page') );
}

Then I tried the following in my second plugin, but the page is wrong redirected instead: admin.php?page=sub_page redirects to /sub_page.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Trying to simulate the issue, it happened the same (wp-admin/submenu_slug), and the solution is to add a priority value in the hook admin_menu.

Here, I'm adding a sub menu to the plugin BackWPup. Note the priority 11:

add_action('admin_menu', 'third_party_submenu_wpse_91377', 11 );

function third_party_submenu_wpse_91377() 
{
    add_submenu_page(
        'backwpup', // Third party plugin Slug 
        'My plugin', 
        'My plugin', 
        'delete_plugins', 
        'third_party_submenu', 
        'plugin_options_wpse_wpse_91377'
    );
}

function plugin_options_wpse_wpse_91377() 
{ 
    echo '<h1>OK</h1>'; 
}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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