简体   繁体   English

在编辑器的 wordpress 管理菜单中隐藏自定义帖子类型链接

[英]Hide custom post type link in wordpress admin menu from Editors

I have a custom post type called "Services" and I would like the custom post type link to show for Admins ONLY and not Editors.我有一个名为“服务”的自定义帖子类型,我希望自定义帖子类型链接仅显示给管理员而不是编辑。

I am aware that I can use "capability_type", however this will not work for me as I don't want to disable the "Services" custom post type from Editors completely.我知道我可以使用“capability_type”,但是这对我不起作用,因为我不想完全从编辑器中禁用“服务”自定义帖子类型。 I am still linking to the "Services" custom post type from a custom admin page, so I still want the Editors to be able to access it.我仍然从自定义管理页面链接到“服务”自定义帖子类型,所以我仍然希望编辑能够访问它。 I just don't want the automatically created link to show up for Editors in the admin menu, however the automatically created link must still show for Admins.我只是不希望在管理菜单中为编辑显示自动创建的链接,但是自动创建的链接仍然必须向管理员显示。

I thought maybe there is a way to put a condition around the following line, but I don't know php that well so I don't know if it can be done.我想也许有一种方法可以在以下行周围放置条件,但我不太了解 php,所以我不知道是否可以完成。

'show_in_menu' => true

Below you can find the code for my custom post type.您可以在下面找到我的自定义帖子类型的代码。

register_post_type( 'services',
    array(
      'labels' => array(
        'name' => __( 'Services' ),
        'singular_name' => __( 'Service' )
      ),
      'public' => true,
      'has_archive' => false,
      'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
      'rewrite' => array('slug' => 'services'),
      'show_in_menu'      => true
    )
  );

Try this one by adding capabilities通过添加功能来试试这个

register_post_type('services', array(
    'labels' => array(
        'name' => __('Services'),
        'singular_name' => __('Service')
    ),
    'public' => true,
    'has_archive' => false,
    'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'),
    'rewrite' => array('slug' => 'services'),
    'show_in_menu' => true,
    'capabilities' => array(
        'edit_post' => 'update_core',
        'read_post' => 'update_core',
        'delete_post' => 'update_core',
        'edit_posts' => 'update_core',
        'edit_others_posts' => 'update_core',
        'delete_posts' => 'update_core',
        'publish_posts' => 'update_core',
        'read_private_posts' => 'update_core'
    ),
        )
);

Use these:使用这些:

function wpse28782_remove_menu_items() {
    if( !current_user_can( 'administrator' ) ):
        remove_menu_page( 'edit.php?post_type=quote' );
    endif;
}
add_action( 'admin_menu', 'wpse28782_remove_menu_items' );

change quote according to your post type name.根据您的帖子类型名称更改quote

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

相关问题 自定义帖子类型未出现在Wordpress管理菜单中 - Custom post type not appearing in Wordpress admin menu WordPress自定义帖子类型未显示在管理菜单中 - Wordpress Custom Post Type Not Showing In Admin Menu WordPress自定义帖子类型管理员嵌套菜单 - WordPress Custom Post Type Admin Nested Menu WordPress管理员:将自定义帖子类型作为父菜单的子菜单放置时,CPT会覆盖父菜单链接 - WordPress Admin: When placing a Custom Post Type as a submenu of a parent menu, the parent menu link is being overridden by the CPT Wordpress 在 wordpress 管理中隐藏自定义帖子类型的子帖子 - Wordpress Hide child posts of custom post type in wordpress admin 自定义WordPress管理菜单:如何使其对编辑者可编辑? - Custom WordPress admin menu: How to make it editable for editors? Wordpress 我的自定义帖子类型的侧栏管理菜单 - Wordpress side bar admin menu for my custom post type WordPress的“自定义帖子类型”未显示在管理菜单中(使用CPT UI创建) - Wordpress Custom Post Type not showing in admin menu (created with CPT UI) 为什么我的Wordpress自定义帖子类型没有显示在管理菜单中 - Why is my Wordpress Custom Post type not displaying in the Admin Menu WordPress:自定义帖子类型类别链接+添加到菜单 - Wordpress: custom post type category link + add to menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM