[resolved] Creating Admin Menus/Screens (7 posts)

  1. ooeygui
    Posted 5 years ago #

    Ok, I've been toiling over this one for quite a while.

    When using the add_menu_page() and add_submenu_page() functions WordPress automatically assumes that you're wanting to put it into the sidebar of the admin screens.

    Is there a way to create a page within the admin section that won't go into the sidebar and wont show the "You don't have permission to access this page" error?

    In the past I've had to modify a sidebar page to do something like this;

    switch ($_REQUEST["var"]){
        case "page1" :
            // Output this
        default :
            // Output the default admin page
  2. Mark / t31os
    Posted 5 years ago #

    Just do what you usually do but unset the menu item after you register the menu page..

    add_action( 'admin_menu' , 'my_pages_etc' );
    function my_pages_etc() {
    	global $menu, $submenu;
    	// Empty values as this is for illustration only
    	add_menu_page( '', '', '', '', '', '', '100' ); // 7th parameter is position in menu array
    	add_submenu_page( ... ); // For illustration only
    	unset( $menu[100] ); // Unset the menu item registered above

    The page will still function, they'll just not be a link to it in the menu... :)

  3. ooeygui
    Posted 5 years ago #

    Nice, I'll have to give that a try. Thanks.

  4. Mark / t31os
    Posted 5 years ago #

    Be sure to global the necessary vars inside your function first, per the example above.

    I actually do alot of menu tweaking for my local installs so this is quite simple stuff for me, if you have any questions, shoot...

    Happy to help in any case.. ;)

  5. ooeygui
    Posted 5 years ago #

    Hmm, this only works on top level admin menus which is ok, but apparently I can only add one top level menu per plugin. I didn't realize this. For some reason when I try to add more than one it forces the link on the menu over to an actual page. For example, "http://www.domain.com/wp-admin/plugin/page" rather than "http://www.domain.com/wp-admin/admin.php?page=plugin/page" and this gives me a 404 error.

    I only need to hide certain items so I need to be able to create more top level menus or be able to hide the sub menus.

  6. ooeygui
    Posted 5 years ago #

    Ok nevermind, I got it.

    When I only define a top level it puts that weird URL in there so I needed to define a submenu underneath it with the same slug.

  7. Mark / t31os
    Posted 5 years ago #

    Small tip, you can create more specific menus by adding thme into the menu array manually..

    Take a look at how menu.php adds the various menu items, you can do the same if you register them inside the action for admin_menu.

    The advantage of adding items manually is that you can have the menu items link offsite, where as the functions for adding items force a URL relative to the current site.

    I've actually added a couple myself.

    Options - links to options.php for the current site (there's no link to it otherwise)
    WordPress 2.9 - links to the 2.9 admin (screenshot is trunk install)
    bbPress - links to installation of bbPress trunk

Topic Closed

This topic has been closed to new replies.

About this Topic