• I’m trying to create custom admin menu, seeing the example here https://codex.www.ads-software.com/Adding_Administration_Menus but it seems not working. When I click on ‘Test Toplevel’ it goes to https://mydomain/mydir/wp-admin/testtoplevel, is this example correct? do I need to put relative path to my plugin directory?

    Here I paste the example on that page:

    // Hook for adding admin menus
    add_action('admin_menu', 'mt_add_pages');
    
    // action function for above hook
    function mt_add_pages() {
    
        // Add a new top-level menu (ill-advised):
        add_menu_page('Test Toplevel', 'Test Toplevel', 8, 'testtoplevel', 'mt_toplevel_page');
    
        // Add a submenu to the custom top-level menu:
        add_submenu_page(__FILE__, 'Test Sublevel', 'Test Sublevel', 8, 'sub-page', 'mt_sublevel_page');
    
        // Add a second submenu to the custom top-level menu:
        add_submenu_page(__FILE__, 'Test Sublevel 2', 'Test Sublevel 2', 8, 'sub-page2', 'mt_sublevel_page2');
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter explor1ng

    (@explor1ng)

    Need help on this.

    What I have tried is:

    add_menu_page('Test Toplevel', 'Test Toplevel', 8, '../wp-content/plugins/myplugindir/myplugin.php');
    add_submenu_page('../wp-content/plugins/myplugindir/myplugin.php', 'Test Sublevel', 'Test Sublevel', 8, '../wp-content/plugins/myplugindir/myplugin.php', 'mt_sublevel_page');
    add_submenu_page('../wp-content/plugins/myplugindir/myplugin.php', 'Test Sublevel 2', 'Test Sublevel 2', 8, 'sub-page2', 'mt_sublevel_page2');

    It works, but looks bad, please tell me if there’s a better way.

    Thread Starter explor1ng

    (@explor1ng)

    can anyone confirm this?

    I’d like to bump this. Facing the same issue here.

    edit:

    I might have hacked it.

    add_menu_page('Artworks', 'Artworks', 9, __FILE__,'printArtworksAdmin');
    add_submenu_page(__FILE__, 'Artworks','Artworks',9,__FILE__,'printArtworksAdmin');
    add_submenu_page(__FILE__, 'Projects','Projects',9,'projectsAdmin','printProjectsAdmin');

    Set the First Submenu’s unique identifier to __FILE__. Very strange behaviour.

    I have some custom code that lives outside the wp-admin folder, and its linked to correctly in menu.php it spits out a page with a form on it. At the top of the page I use:
    <?php
    require_once( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-admin/admin.php’);
    $title = __(‘Edit Inns’);
    $this_file = ‘inn.php’;
    $parent_file = ‘inn.php’;
    require_once( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-admin/admin-header.php’);
    ?>
    to pull in the wordpress admin menu, but its not pulling in my plugin menu items (specifically cforms II) any suggestions?

    @dazzer

    Why would you set the unique identifier to __FILE__?

    Creating custom admin menus is really very easy.

    __FILE__ refers to the file that will handle the display of the admin page you wish to create. The submenu’s unique identifier is just a name that will be sent via GET to the page that handles it, hence why it has to be unique, and not __FILE__…

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Setup Top Level Admin Menu’ is closed to new replies.