Adding admin top-level menus

时间:2016-02-16 作者:uncovery

我正在写一个插件(Github Link) 并且在设置管理菜单的标题时遇到问题。

我用add\\u menu\\u page定义了一个顶部标题菜单(link to code, same as below) 和2个子菜单的add\\u submenu\\u页面,但我在管理菜单中得到4行,主菜单,然后是小菜单中的那一行(具有相同的链接目标),然后是2个子菜单。

add_action(\'admin_menu\', \'unc_gallery_admin_menu\');
function unc_gallery_admin_menu() {
    // the main page where we manage the options
    add_menu_page(
        \'Uncovery Gallery Options\', // $page_title,
        \'Uncovery Gallery\', // $menu_title,
        \'manage_options\', // $capability,
        \'unc_gallery_admin_menu\', // $menu_slug,
        \'unc_gallery_options\' // $function, $icon_url, $position
    );
    // where we upload images
    $upload_page_hook_suffix = add_submenu_page(
        \'unc_gallery_admin_menu\', // $parent_slug
        \'Upload Images\',  // $page_title
        \'Upload Images\', // $menu_title
        \'manage_options\', // capability, manage_options is the default
        \'unc_gallery_admin_upload\', // menu_slug
        \'unc_uploads_form\' // function
    );
    add_action(\'admin_print_scripts-\' . $upload_page_hook_suffix, \'unc_gallery_admin_add_css_and_js\');
    // where we list up all the images
    $view_page_hook_suffix = add_submenu_page(
        \'unc_gallery_admin_menu\', // $parent_slug
        \'View Images\',  // $page_title
        \'View Images\', // $menu_title
        \'manage_options\', // capability, manage_options is the default
        \'unc_gallery_admin_view\', // menu_slug
        \'unc_gallery_admin_display_images\' // function
    );
    add_action(\'admin_print_scripts-\' . $view_page_hook_suffix, \'unc_gallery_admin_add_css_and_js\');    
}

enter image description here

我怎样才能更改第二个的标题;“展示画廊”;或者最好将其移除?

谢谢

2 个回复
最合适的回答,由SO网友:Mayeenul Islam 整理而成

可以使用以下脚本更改第一个子菜单文本:

function __test_menu() {
    global $submenu;
    //var_dump($submenu); //check yourself
    $submenu[\'unc_gallery_admin_menu\'][0][0] = __( \'Test\', \'textdomain\' );
}
add_action( \'admin_menu\', \'__test_menu\' );
请注意,您的插件很容易出错,会抛出警告消息。始终使用WP_DEBUGtrue. 不要写硬核文本,最好把它们写进去gettext functions. i、 e.写入__( \'Test\', \'textdomain\' ); 而不是\'Test\';. 它会让你的插件翻译做好准备。祝你好运

SO网友:Devendra Sharma

You can use.

 add_submenu_page(\'unc_gallery_admin_menu\', \'\', \'\', \'read\',\'unc_gallery_admin_menu\', \'unc_gallery_options\');

相关推荐