将角色分配给wordpress自定义帖子类型

时间:2018-02-22 07:39:51

标签: php wordpress custom-post-type

我的自定义post_type circular以及自定义角色circular_uploadercapabilities无法正常工作请帮我简短说明。现在它们像后期功能一样显示,但我需要制作独特的

 Create posts
 Delete others posts
 Delete posts
 Delete private posts
 Delete published posts
 Edit others posts
 Edit posts
 Edit private posts
 Edit published posts
 Publish posts
 Read private posts

上述功能需要像下面的功能一样改变

 Create circulars
 Delete others circulars
 Delete circulars
 Delete private circulars
 Delete published circulars
 Edit others circulars
 Edit circulars
 Edit private circular
 Edit published circulars
 Publish circulars
 Read private circulars 

我的自定义帖子类型

$args = array(
    'labels'        => $labels,
    'description'   => 'Holds our circulars and circular specific data',
    'hierarchical'        => false,
    'public'              => true,
    'supports'            => array( 'title', 'excerpt' ),
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'menu_icon'           => 'dashicons-editor-unlink',
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'map_meta_cap'        => true,
    'capabilities' => array(
      'create_post'          => 'create_circular', 
      'edit_post'          => 'edit_circular', 
      'read_post'          => 'read_circular', 
      'delete_post'        => 'delete_circular', 
      'edit_posts'         => 'edit_circulars', 
      'edit_others_posts'  => 'edit_others_circulars', 
      'publish_posts'      => 'publish_circulars',       
      'read_private_posts' => 'read_private_circulars', 
      'create_posts'       => 'create_circulars', 
    ),
  );
  register_post_type( 'circular', $args ); 
}

添加自定义角色

add_role("circular_uploader", "Circular Uploader", array(
    'read' => true,
    'upload_files'=>true,
    'edit_posts' => false,
    'edit_pages' => false,
    'edit_others_posts' => false,
    'create_posts' => false,
    'manage_categories' => false,
    'publish_posts' => false,
    'edit_themes' => false,
    'install_plugins' => false, 
    'update_plugin' => false,
    'update_core' => false, 
    'create_circular' => true,
    'edit_circular' => true,
    'edit_others_circular' => true,
    'delete_circular' => true,
    'delete_others_circular' => true,
    'publish_circular' => true
));

为角色分配功能

function add_circular_caps() {

 // gets the administrator role register_activation_hook
    $roles = get_role( 'circular_uploader' );

    $roles ->add_cap( 'create_circular' ); 
    $roles ->add_cap( 'edit_circular' ); 
    $roles ->add_cap( 'edit_circulars' ); 
    $roles ->add_cap( 'edit_other_circulars' ); 
    $roles ->add_cap( 'publish_circulars' ); 
    $roles ->add_cap( 'read_circular' ); 
    $roles ->add_cap( 'read_private_circulars' ); 
    $roles ->add_cap( 'delete_circular' ); 
}
add_action( 'admin_init', 'add_circular_caps');

1 个答案:

答案 0 :(得分:0)

我建议使用插件,User Role Editor效果很好。