Search code examples
phpwordpresswordpress-plugin-creationwordpress-hook

WordPress admin submenu links incorrectly ordered


In the plugin I'm working on, I have an admin menu item, with several submenus depending on whether certain features of the plugin are enabled. Because of this, the submenus are declared in different classes.

The way I'm declaring the submenus:

add_action("admin_menu", array($this,"a_function"));
function a_function(){
    add_submenu_page(
    "a_parent_slug", //parent slug
    __("a title","a-text-domain"), //page title
    __("a title","a-text-domain"), //menu title
    "manage_options", //capability
    "a_slug", //menu slug
    array($this, "a_callback_function"), //callback
    40 //position
    );
}

The positions are all declared as integers.

The order they're appearing in the actual menu, however, is this:

  • 10
  • 20
  • 30
  • 31
  • 32
  • 50
  • 40

Using floats instead of integers made it worse, they appeared in an all but random order.

Am I missing something? Or is this a bug I should be raising on Trac?


Solution

  • Solution: the position in the function doesn't appear to do squat - changing the priority of the action did the trick. eg.

    add_action("admin_menu", array($this,"a_function"),40);
    function a_function(){
        add_submenu_page(
        "a_parent_slug", //parent slug
        __("a title","a-text-domain"), //page title
        __("a title","a-text-domain"), //menu title
        "manage_options", //capability
        "a_slug", //menu slug
        array($this, "a_callback_function"), //callback
        40 //position
        );
    }