我有一个自定义帖子类型,我希望订阅者能够编辑和删除他们自己的帖子。我有下一个代码:
function agents_create_post_type() {
$labels = array(
'name' => __( 'Agents', 'ee' ),
'singular_name' => __( 'Agent', 'ee' ),
'add_new' => __( 'Add New', 'ee' ),
'add_new_item' => __( 'Add New Agent', 'ee' ),
'edit_item' => __( 'Edit Agent', 'ee' ),
'new_item' => __( 'New Agent', 'ee' ),
'all_items' => __( 'All Agents', 'ee' ),
'view_item' => __( 'View Agent', 'ee' ),
'search_items' => __( 'Search Agent', 'ee' ),
'not_found' => __( 'No agents found', 'ee' ),
'not_found_in_trash' => __( 'No agents found in Trash', 'ee' ),
'parent_item_colon' => '',
'menu_name' => __( 'Agents', 'ee' ),
);
$capabilities = array(
'publish_posts' => 'publish_agents',
'edit_posts' => 'edit_agents',
'edit_others_posts' => 'edit_others_agents',
'delete_posts' => 'delete_agents',
'delete_others_posts' => 'delete_others_agents',
'read_private_posts' => 'read_private_agents',
'edit_post' => 'edit_agent',
'delete_post' => 'delete_agent',
'read_post' => 'read_agent'
);
register_post_type( 'agent',
array(
'labels' => $labels,
'rewrite' => array(
'slug' => __( 'agents', 'ee' )
),
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' ),
'public' => true,
'has_archive' => true,
'menu_position' => 32,
'map_meta_cap'=>true,
'capabilities' => $capabilities,
'menu_icon' => get_template_directory_uri() .'/img/agents.png',
)
);
}
add_action( 'init', 'agents_create_post_type' );
function add_capability() {
$admins = get_role( 'administrator' );
$admins->add_cap( 'publish_agents' );
$admins->add_cap( 'edit_agents' );
$admins->add_cap( 'edit_others_agents' );
$admins->add_cap( 'delete_agents' );
$admins->add_cap( 'delete_others_agents' );
$admins->add_cap( 'read_private_agents' );
$admins->add_cap( 'edit_agent' );
$admins->add_cap( 'delete_agent' );
$admins->add_cap( 'read_agent' );
$subscriber = get_role( 'subscriber' );
$subscriber->add_cap( 'edit_agents' );
$subscriber->add_cap( 'delete_agents' );
}
add_action( 'admin_init', 'add_capability');
完成后,我在面板控件中获得了订阅者菜单以添加和查看代理,但是当我列出它们时,即使我已经为订阅者指定了权限,一旦管理员发布了帖子,似乎链接编辑、删除 por每个帖子都不再出现,我认为上面的权限就足够了。任何线索将不胜感激!