The MU forums have moved to WordPress.org

add_menu_page hook not working (7 posts)

  1. tassoman
    Member
    Posted 17 years ago #

    Hello to all, I'm just trying to create a site-wide plugin with admin inteface into mu-plugins dir.

    admin_menu loads the add_menu_page item, but when i click on it to get the menu page, i get an error.

    The linked url is http://test.domain.tld/wp-admin//var/www/domain.tld/htdocs/wp-content/mu-plugins/the-plugin-file.php

    That you see.. doesn't exists. It should be something like:
    http://test.domain.tld/wp-admin/admin.php?page=my-plugin-page.php

  2. sycophant
    Member
    Posted 17 years ago #

    I've just encountered this too.

    It seems that the plugin_page_hook stuff is hardcoded with the wp-content/plugins directory and does not recognise the mu-plugins page.

    Did you find a way around this?

  3. andrea_r
    Moderator
    Posted 17 years ago #

    Mmmmm... our Theme Stats plugin is in the mu-plugins folder and adds an admin menu. Why not have a look at it?

    And I'm assuming you read this:
    http://codex.wordpress.org/Adding_Administration_Menus
    but stickign the link there just the same. :)

  4. sycophant
    Member
    Posted 17 years ago #

    I'm trying to create (well have created) a top-level menu for my plugin, as it will have a number of configurable sections.

    The functions for adding sub-menus as described in the codex work in MU, but not the top-level menus.

    To test this, copy the example script from the codex page and put it in the mu-plugins folder.

    Tracing back through the source (Zend Studio's 'Go To Declaration' is great!!) brings me to the plugin_page_hook method where it seems to be dependent on the plugin being in the /plugins/ not /mu-plugins/.

    My workaround was to declare my menu settings into the global $menu variable (being careful not to clobber other existing menus).

    add_action('admin_menu','addmenu');
    function addmenu() {
    global $submenu, $menu;
    $menu[2] = array(__('Premium Blogs'), 'premium', 'premium.php');
    $submenu['premium.php'][0] = array( __('Main'), '10', 'premium.php' );
    $submenu['premium.php'][1] = array( __('Plugins'), '10', 'premium-plugins.php' );
    }

    This means, however, that I need to create menu pages that have to be placed in the wp-admin directory. Also I am potentially clobbering any other menu that is placed at index 2 in the top level menu.

  5. andrea_r
    Moderator
    Posted 17 years ago #

    In the codex, they strongly discourage top-level menus, and in my own attempts - and looking in the regular forums - I found out that it's damn near impossible without a lot of convoluted bending-over-backwards.

    Sure, there codex example works for a tl menu, but even changing what they have doesn't. I'd go poke around the regular forums becuase there's stuff there, but I wouldn't hold my breath either. (or I'd start making lots of coffee now.)

  6. lunabyte
    Member
    Posted 17 years ago #

    Actually, it isn't "that" difficult. I did it for my Menu Management plugin, mainly due to the current sub-menu structure it has, as well as for future expansion.

    It was something I debated about heavily though, then came to the conclusion that it was the better option due to the sub-menu's now, ones to perhaps come later, and that it was adding a new primary function on par with links, etc.

  7. chmac
    Member
    Posted 16 years ago #

    I've just come across the same problem. I've submitted a patch which allows plugins installed in mu-plugins to add pages as normal. One less thing to re-code when working with WPMU! :)

About this Topic