WordPress.org

Ready to get started?Download WordPress

Forums

Plugins and adding menu items to the Admin? (9 posts)

  1. Beau Collins
    Member
    Posted 9 years ago #

    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.

  2. Beau Collins
    Member
    Posted 9 years ago #

    Ignore the html characters in the example function.

  3. Joshua Sigar
    Member
    Posted 9 years ago #

  4. Beau Collins
    Member
    Posted 9 years ago #

    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','');`

  5. Anonymous
    Unregistered
    Posted 9 years ago #

    p

  6. Beau Collins
    Member
    Posted 9 years ago #

    alphaoide that is a much better solution.

  7. Beau Collins
    Member
    Posted 9 years ago #

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

  8. Joshua Sigar
    Member
    Posted 9 years ago #

    no clue

  9. Beau Collins
    Member
    Posted 9 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.