为什么我的自定义帖子类型仅针对我的自定义用户角色显示?

问题描述 投票:0回答:1

我已经为我的餐厅创建了自定义帖子类型。当前仅针对我的restaurant_owner自定义用户角色显示。我希望它也可以向管理员显示。

我在做什么错?

自定义帖子类型:

add_action( 'init', 'pt_restaurant');
function pt_restaurant() { 
register_post_type( 'bounty_product', array(
  'labels' => array(
     'name' => 'Restaurants',
     'singular_name' => 'Restaurant',
     'add_new' => 'Add New',
     'add_new_item' => 'Add New Restaurant',
     'edit' => 'Edit',
     'edit_item' => 'Edit Restaurant',
     'new_item' => 'New Restaurant',
     'view' => 'View',
     'view_item' => 'View Restaurant',
     'search_items' => 'Search Restaurants',
     'not_found' => 'No Restaurants found',
     'not_found_in_trash' => 'No Restaurants found in Trash',
     'parent' => 'Parent Restaurant'),
  'description' => 'Used for the Restaurant section',
  'public' => true,
  'capability_type' => array('bounty_product','bounty_products'),
  'map_meta_cap' => true,
  'show_in_menu' => true,
  'menu_position' => 20,
  'has_archive' => true,
  'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),

));

自定义用户角色:

add_action('init', 'restaurant_owner_user_role');
function restaurant_owner_user_role() {
    add_role('restaurant_owner', 'Restaurant Owner',
        array (
                'edit_bounty_product' => true,
                'delete_bounty_product' => false,
                'read_bounty_product' => true,
                'publish_bounty_products' => false,
                'edit_bounty_products' => true,
                'edit_others_bounty_products' => false,
                'delete_bounty_products' => false,
                'delete_others_bounty_products' => false,
                'read_private_bounty_products' => false,            

                'read' => true,
        )
    );
}
php wordpress custom-post-type user-roles
1个回答
0
投票

您只为自定义用户角色提供功能,这就是为什么管理员无法编辑/更新/删除 CPT的原因。尝试在functions.php中使用以下代码]

function add_theme_caps() {
    // gets the administrator role
    $admins = get_role( 'administrator' );

    $admins->add_cap( 'edit_bounty_product' ); 
    $admins->add_cap( 'delete_bounty_product' ); 
    $admins->add_cap( 'read_bounty_product' ); 
    $admins->add_cap( 'publish_bounty_products' ); 
    $admins->add_cap( 'edit_bounty_products' ); 
    $admins->add_cap( 'edit_others_bounty_products' ); 
    $admins->add_cap( 'delete_bounty_products' ); 
    $admins->add_cap( 'delete_others_bounty_products' ); 
    $admins->add_cap( 'read_private_bounty_products' ); 
    $admins->add_cap( 'delete_gallery' ); 
}
add_action( 'init', 'add_theme_caps');
© www.soinside.com 2019 - 2024. All rights reserved.