你肯定需要设置map_meta_cap
到true
而不是false来创建自定义功能。
我还没有看到\'capability_type\' => [\'note\',\'notes\']
以前创建功能的方式—可能是简写,但如果只是更改map_meta_cap
如果不起作用,您可能需要从长远的角度来解释一切:
<?php
$args = array(
\'labels\' => $labels,
\'public\' => false,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'has_archive\' => false,
\'menu_position\' => null,
// The most crucial change: true
\'map_meta_cap\' => true,
// Possibly required: spelling out every capability individually
\'capabilities\' => array(
\'edit_post\' => \'edit_note\',
\'read_post\' => \'read_note\',
\'delete_post\' => \'delete_note\',
\'create_posts\' => \'create_notes\',
\'delete_posts\' => \'delete_notes\',
\'delete_others_posts\' => \'delete_others_notes\',
\'delete_private_posts\' => \'delete_private_notes\',
\'delete_published_posts\' => \'delete_published_notes\',
\'edit_posts\' => \'edit_notes\',
\'edit_others_posts\' => \'edit_others_notes\',
\'edit_private_posts\' => \'edit_private_notes\',
\'edit_published_posts\' => \'edit_published_notes\',
\'publish_posts\' => \'publish_notes\',
\'read_private_posts\' => \'read_private_notes\'
),
\'rewrite\' => [ \'slug\' => \'note\', \'with_front\' => false ],
\'supports\' => [ \'editor\' ],
\'menu_icon\' => \'dashicons-format-aside\',
);
register_post_type( \'note\', $args );
?>
您可能还想授予自定义角色一些其他功能:
<?php
$role = get_role( \'my_custom_role\' );
// Read (front end) all post types
$role->add_cap(\'read\');
// Adjust their dashboard
$role->add_cap(\'edit_dashboard\');
// Upload files
$role->add_cap(\'upload_files\');
// See the list of users (but not manage them)
$role->add_cap(\'list_users\');
// Allow taxonomy management - Categories and custom taxonomies
$role->add_cap(\'manage_categories\');
// Use the Customizer
$role->add_cap(\'edit_theme_options\');
// Only if you really need to, allow them to paste in HTML/JS
$role->add_cap(\'unfiltered_html\');
?>
至少我通常会向自定义角色授予“读取”权限,以便他们可以看到站点的前端。