从管理菜单中删除自定义分类

时间:2017-10-06 作者:Leff

我已经制定了自定义分类法,用于几种不同的帖子类型:

<?php
add_action(\'init\', function() {
    register_post_type(\'intranet-categories\', [
        \'labels\' => [
            \'name\'                  => \'Kategorier\',
            \'singular_name\'         => \'Kategorier\',
            \'menu_name\'             => \'Kategorier\',
            \'name_admin_bar\'        => \'Kategorier\',
            \'add_new\'               => \'Legg til ny\',
            \'add_new_item\'          => \'Ny Kategori\',
            \'new_item\'              => \'Ny Kategori\',
            \'edit_item\'             => \'Rediger Kategori\',
            \'view_item\'             => \'Vis Kategori\',
            \'all_items\'             => \'Alle Kategorier\',
            \'search_items\'          => \'Søk\',
            \'parent_item_colon\'     => \'Forelder\',
            \'not_found\'             => \'Fant ingen Kategori.\',
            \'not_found_in_trash\'    => \'Fant ingen Kategori i søppelkassen.\',
        ],
        \'description\'           => \'Kategori\',
        \'public\'                => true,
        \'publicly_queryable\'    => true,
        \'show_ui\'               => true,
        \'show_in_menu\'          => true,
        \'query_var\'             => true,
        \'rewrite\'               => [\'slug\' => \'intranet-categories\'],
        \'capability_type\'       => \'post\',
        \'has_archive\'           => true,
        \'hierarchical\'          => false,
        \'menu_position\'         => null,
        \'menu_icon\'             => \'dashicons-editor-ol\',
        \'supports\'              => [\'title\', \'editor\', \'excerpt\', \'thumbnail\'],
        \'capability_type\' => \'custom_post_type\',
        \'capabilities\' => [\'create_posts\' => false],
    ]);

    register_taxonomy(\'department\', [\'intranet-categories\', \'intranet-post\'], [
        \'labels\' => [
            \'name\'              => \'Avdeling\',
            \'singular_name\'     => \'Avdeling\',
            \'search_items\'      => \'Søk\',
            \'all_items\'         => \'Alle avdelinger\',
            \'parent_item\'       => \'Forelder\',
            \'parent_item_colon\' => \'Forelder\',
            \'edit_item\'         => \'Rediger avdeling\',
            \'update_item\'       => \'Oppdater avdeling\',
            \'add_new_item\'      => \'Opprett avdeling\',
            \'new_item_name\'     => \'Ny avdeling\',
            \'menu_name\'         => \'Avdelinger\',
        ],
        \'hierarchical\'      => true,
        \'show_ui\'           => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
        \'rewrite\'           => [\'slug\' => \'avdeling\'],
    ]);

    register_taxonomy(\'region\', [\'intranet-categories\', \'intranet-post\'], [
        \'labels\' => [
            \'name\'              => \'Region\',
            \'singular_name\'     => \'Region\',
            \'search_items\'      => \'Søk\',
            \'all_items\'         => \'Alle region\',
            \'parent_item\'       => \'Forelder\',
            \'parent_item_colon\' => \'Forelder\',
            \'edit_item\'         => \'Rediger Region\',
            \'update_item\'       => \'Oppdater Region\',
            \'add_new_item\'      => \'Opprett Region\',
            \'new_item_name\'     => \'Ny Region\',
            \'menu_name\'         => \'Regioner\',
        ],
        \'hierarchical\'      => true,
        \'show_ui\'           => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
        \'rewrite\'           => [\'slug\' => \'avdeling\'],
    ]);

    register_taxonomy(\'industry\', [\'intranet-categories\', \'intranet-post\'], [
        \'labels\' => [
            \'name\'              => \'Bransje\',
            \'singular_name\'     => \'Bransje\',
            \'search_items\'      => \'Søk\',
            \'all_items\'         => \'Alle bransjer\',
            \'parent_item\'       => \'Forelder\',
            \'parent_item_colon\' => \'Forelder\',
            \'edit_item\'         => \'Rediger bransje\',
            \'update_item\'       => \'Oppdater bransje\',
            \'add_new_item\'      => \'Opprett bransje\',
            \'new_item_name\'     => \'Ny bransje\',
            \'menu_name\'         => \'Bransjer\',
        ],
        \'hierarchical\'      => true,
        \'show_ui\'           => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
            \'rewrite\' => [\'slug\' => \'bransje\'],
        ]
    );

    register_taxonomy(\'role\', [\'intranet-categories\', \'intranet-post\'], [
        \'labels\' => [
            \'name\'              => \'Rolle\',
            \'singular_name\'     => \'Rolle\',
            \'search_items\'      => \'Søk\',
            \'all_items\'         => \'Alle roller\',
            \'parent_item\'       => \'Forelder\',
            \'parent_item_colon\' => \'Forelder\',
            \'edit_item\'         => \'Rediger rolle\',
            \'update_item\'       => \'Oppdater rolle\',
            \'add_new_item\'      => \'Opprett rolle\',
            \'new_item_name\'     => \'Ny rolle\',
            \'menu_name\'         => \'Roller\',
        ],
        \'hierarchical\'      => true,
        \'show_ui\'           => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
            \'rewrite\' => [\'slug\' => \'rolle\'],
        ]
    );

    register_taxonomy(\'company\', [\'intranet-categories\', \'intranet-post\'], [
        \'labels\' => [
            \'name\'              => \'Selskap\',
            \'singular_name\'     => \'Selskap\',
            \'search_items\'      => \'Søk\',
            \'all_items\'         => \'Alle selskaper\',
            \'parent_item\'       => \'Forelder\',
            \'parent_item_colon\' => \'Forelder\',
            \'edit_item\'         => \'Rediger selskap\',
            \'update_item\'       => \'Oppdater selskap\',
            \'add_new_item\'      => \'Opprett selskap\',
            \'new_item_name\'     => \'Ny selskap\',
            \'menu_name\'         => \'Selskaper\',
        ],
        \'hierarchical\'      => true,
        \'show_ui\'           => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
            \'rewrite\' => [\'slug\' => \'selskap\'],
        ]
    );
});
我想做的是在管理菜单中隐藏创建的自定义分类法intranet-post 键入,并且仅在的“管理”菜单中可见intranet-categories, 因为我只想编辑这些自定义分类法,并从intranet-categories 岗位类型。我试过这样做:

function remove_taxonomy_submenu_pages() {
    $categories = get_object_taxonomies(\'intranet-categories\');
    foreach($categories as $category) {
        remove_menu_page( \'edit.php\', \'edit-tags.php?taxonomy=\' . $category . \'&post_type=intranet-post\' );
    }
}

add_action( \'admin_menu\', \'remove_taxonomy_submenu_pages\', 20);
但是,这不起作用,正确的方法是什么?

2 个回复
SO网友:Kuliraj

正在引用register\\u taxonomy()https://codex.wordpress.org/Function_Reference/register_taxonomy

show_in_menu在“管理”菜单中显示分类的位置。show\\u ui必须为true。

默认值:show\\u ui参数的值

“错误”-不显示在管理菜单中

“true”-显示为关联对象类型的子菜单

SO网友:Randomer11

您可以使用以下插件:https://en-gb.wordpress.org/plugins/admin-menu-editor/

它允许您删除不同角色组的菜单项。与用户角色编辑器插件一起使用,您可以缩小所有内容,为特定角色创建一个干净的管理面板

结束

相关推荐