简体   繁体   English

WordPress 管理子菜单链接顺序错误

[英]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 10
  • 20 20
  • 30 30
  • 31 31
  • 32 32
  • 50 50
  • 40 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?或者这是我应该在 Trac 上提出的错误?

Solution: the position in the function doesn't appear to do squat - changing the priority of the action did the trick.解决方案:function 中的 position 似乎没有下蹲 - 改变动作的优先级就可以了。 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
    );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM