我正在创建一个新闻插件,因为我想要自定义帖子类型的用户功能,我的代码就在这里
function news_blurb_custom_type() {
$labels = array(
'name' => 'Blurbs',
'singular_name' => 'Blurb',
'menu_name' => 'Blurbs',
'name_admin_bar' => 'Blurb',
'add_new' => 'Add New',
'add_new_item' => 'Add New Blurb',
'new_item' => 'New Blurb',
'edit_item' => 'Edit Blurb',
'view_item' => 'View Blurb',
'all_items' => 'All Blurbs',
'search_items' => 'Search Blurbs',
'parent_item_colon' => 'Parent Blurbs:',
'not_found' => 'No blurbs found.',
'not_found_in_trash' => 'No blurbs found in Trash.'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => false, //<--- HERE
'query_var' => true,
'rewrite' => array( 'slug' => 'all_news_blurbs' ),
'capability_type' => 'blurbs',
'capabilities' => array(
'edit_post' => 'edit_single_blurbs',
'read_post' => 'read_single_blurbs',
'delete_post' => 'delete_single_blurbs',
'edit_posts' => 'edit_blurbs',
'edit_others_posts' => 'edit_others_blurbs',
'publish_posts' => 'publish_blurbs',
'read_private_posts' => 'read_private_blurbs',
'delete_posts' => 'delete_blurbs',
'delete_private_posts' => 'delete_private_blurbs',
'delete_published_posts' => 'delete_published_blurbs',
'delete_others_posts' => 'delete_others_blurbs',
'edit_published_posts' => 'edit_published_blurbs',
'read_published_posts' => 'read_published_blurbs',
),
'map_meta_cap' => true,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail')
);
register_post_type( 'all_news_blurbs', $args );
}
add_action( 'init', 'news_blurb_custom_type' );
我的用户角色代码
add_role('post_writer', 'Post writer', array(
//* Meta capabilities
'read' => true,
'edit_single_blurbs' => true,
'read_single_blurbs' => true,
'delete_single_blurbs' => true,
//* Primitive capabilities used outside of map_meta_cap()
'edit_blurbs' => true,
'edit_others_blurbs' => true,
'publish_blurbs' => true,
'read_private_blurbs' => true,
//* Primitive capabilities used within of map_meta_cap()
'delete_blurbs' => true,
'delete_private_blurbs' => true,
'delete_published_blurbs' => true,
'delete_others_blurbs' => true,
'edit_private_blurbs' => true,
'edit_published_blurbs' => true,
'read_published_blurbs' => true
));
function add_circular_caps() {
$roles = get_role( 'post_writer' );
$roles ->add_cap( 'edit_single_blurbs' );
$roles ->add_cap( 'read_single_blurbs' );
$roles ->add_cap( 'delete_single_blurbs' );
$roles ->add_cap( 'edit_blurbs' );
$roles ->add_cap( 'edit_others_blurbs' );
$roles ->add_cap( 'publish_blurbs' );
$roles ->add_cap( 'read_private_blurbs' );
$roles ->add_cap( 'delete_blurbs' );
$roles ->add_cap( 'delete_private_blurbs' );
$roles ->add_cap( 'delete_published_blurbs' );
$roles ->add_cap( 'delete_others_blurbs' );
$roles ->add_cap( 'edit_published_blurbs' );
$roles ->add_cap( 'read_published_blurbs' );
}
add_action( 'admin_init', 'add_circular_caps');
当我以帖子编写者身份登录时,自定义帖子类型未显示
我已经改变了所有相似之处仍然没有用,但我在主题函数中使用它。用户角色显示但是对于插件它没有显示。