[英]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.