MENU_ORDER不能处理以admin.php开头的插件

时间:2013-12-11 作者:codeprokanner

我正在过滤menu\\u order挂钩(codex链接->http://codex.wordpress.org/Plugin_API/Filter_Reference/menu_order) 更改“管理”菜单中“我的链接”的顺序。目前,以admin开头的slug无法进行排序。因此,带有slug“admin.php?page=custom\\u settings\\u page”的设置页面将位于列表的底部。有人知道这方面的解决方法吗?

//change admin menu order
add_filter(\'custom_menu_order\', \'my_custom_menu_order\'); // Activate custom_menu_order
add_filter(\'menu_order\', \'my_custom_menu_order\');

function my_custom_menu_order($menu_ord){

if(!$menu_ord) return true;
return array(
    \'index.php\', //dashboard
    \'separator1\', //first separator
    \'edit.php\', //posts
    \'edit.php?post_type=custom_post_type1\', //custom post type 1
    \'edit.php?post_type=custom_post_type2\', //custom post type 2
    \'edit.php?post_type=custom_post_type3\', //custom post type 3
    \'upload.php\', //media
    \'separator2\', //second separator
    \'admin.php?page=gf_edit_forms\', //THIS GOES TO THE BOTTOM
    \'edit.php?post_type=page\', //pages
    \'edit-comments.php\', //comments
    \'separator-last\', //last separator
    \'themes.php\', //appearance
    \'admin.php?page=custom_settings_page\', //THIS GOES TO THE BOTTOM
    \'plugins.php\', //plugins
    \'users.php\', //users
    \'tools.php\', //tools
    \'options-general.php\' //WordPress options
);

}

1 个回复
SO网友:Matt Tang

删除“admin”。php?页面=\'来自这些值。

\'管理员。php?page=custom\\u settings\\u page”应为“custom\\u settings\\u page”

\'管理员。php?页面=gf\\u edit\\u forms”应为“gf\\u edit\\u forms”

以admin开头的值。php仅在全局默认菜单顺序数组(global$default\\u menu\\u order)中设置其参数。

因此,当排序发生在自定义菜单顺序数组和全局默认菜单顺序数组之间时,它将无法正确匹配以admin开头的条目。php。

默认行为是将自定义数组之外的任何内容添加到底部。

更正的代码:

//change admin menu order
add_filter(\'custom_menu_order\', \'my_custom_menu_order\'); // Activate custom_menu_order
add_filter(\'menu_order\', \'my_custom_menu_order\');

function my_custom_menu_order($menu_ord){

    if(!$menu_ord) return true;
    return array(
        \'index.php\', //dashboard
        \'separator1\', //first separator
        \'edit.php\', //posts
        \'edit.php?post_type=custom_post_type1\', //custom post type 1
        \'edit.php?post_type=custom_post_type2\', //custom post type 2
        \'edit.php?post_type=custom_post_type3\', //custom post type 3
        \'upload.php\', //media
        \'separator2\', //second separator
        \'gf_edit_forms\', //fixed
        \'edit.php?post_type=page\', //pages
        \'edit-comments.php\', //comments
        \'separator-last\', //last separator
        \'themes.php\', //appearance
        \'custom_settings_page\', //fixed
        \'plugins.php\', //plugins
        \'users.php\', //users
        \'tools.php\', //tools
        \'options-general.php\' //WordPress options
    );

}

结束

相关推荐