• I’m trying to make a plug-in (actually add custom functionality) with administration settings for the post by email, and a custom wish list plug-in. What I’d like to do is add an area to the menu if they activate the plug-in. This menu would access an admin page I’ve created. Is this possible?
    I saw in the menu.php that the navigation is an array $menu where each row contains an array for the name, the administration level, and the link.
    So, I tried making a function to add to the wp-admin menu with

    function ep_adminlink(){
    $menu[55] = array(_(‘Email Post’), 5, ’email.php’);
    $submenu …
    }

    Where submenu hopefully creates the menu choices on my email.php page.
    I then load this with an add_action into the admin_head like the Hello Dolly plugin.
    It looks like my $menu array values are killed before menu.php even loads.
    Is this right? Am I doing the right thing? Is this possible?
    (I most likely put this in the wrong topic, but I’m using 1.3 only)

Viewing 9 replies - 1 through 9 (of 9 total)
  • You need to declare the gloabal variables $menu and $submenu. The way you have your function they are local variables only to the ep_adminlink() function.
    Example


    function add_to_menu(){
    global $menu, $submenu;<br/><br/>
    $menu[15] = array(__('Cool Plugin'), 1, 'plugin.php');
    $submenu['plugin.php'][0] = array(__('Subitem 1'), 1, 'other.php');<br/><br/>

    In order to get the submen to work. You must set the $parent_file variable for each script you are adding. For instance, in the plugin.php file, before the require_once('admin-head.php') line put:
    $parent_file = 'plugin.php';
    Use this line for every plugin file that will share the same parent menu item. So in the above example, plugin.php and other.php should both have $parent_file='plugin.php'.
    All of these files must also be in the wp-admin folder.

    Ignore the html characters in the example function.

    Wait there is more!
    You have to register your function with add_action().
    So continuing with the example from above, somewhere in your plugin script (the php file in your plugin folder) put this line:

    add_action('admin_menu','add_to_menu');

    Replace 'add_to_menu' with whatever the name of the function you have manipulating the admin menu.
    If you want the order of the menu to be correct, in the wp-admin/menu.php file, move the line:

    ksort($menu);

    And place after the line:

    do_action(‘admin_menu’,”);`

    p

    alphaoide that is a much better solution.

    I am getting a function does not exist error, what release are those hooks available?
    I’m using WP 1.3 alpha 5

    no clue

    My admin-functions.php file only has the add_options_pages() function. Perhaps I need to get the one off the CVS.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Plugins and adding menu items to the Admin?’ is closed to new replies.