After setting up a new Role, CPT and capabilities, the new role can't see the featured image

Registering the custom post type:$labels = array('name' => 'tananyags','singular_name'

Registering the custom post type:

$labels = array(
  'name' => 'tananyags',
  'singular_name' => 'etananyag',
  'menu_name' => 'E-Tananyagok',
  'name_admin_bar' => 'Add new',
  'add_new' => 'Add New',
  'add_new_item' => 'Add New Item',
  'new_item' => 'New',
  'edit_item' => 'Edit',
  'view_item' => 'View Item',
  'all_items' => 'All',
  'search_items' => 'Search',
  'parent_item_colon' => 'Parent: ??',
  'not_found' => 'No item found',
  'not_found_in_trash' => 'No item found in the trash',
);

$args = array (
  'labels' => $labels,
  'public' => true,
  'publicly_quaryable' => true,
  'show_ui' => true,
  'show_in_menu' => true,
  'query_var' => false,
  'hierarchical'  => false,
  'capability_type'     => array('etananyag','tananyags'),
  'has_archive' => true,
  'menu_position' => 7,
  'rewrite' => array( 'slug' => 'etananyag'),
  'supports' => array( 'title', 'editor', 'thumbnail'),
  'taxonomies'  => array( 'category' ),
  'menu_icon' => 'dashicons-book-alt',
  'show_in_rest' => true,
  'capabilities' => array(
    'edit_post' => 'edit_etananyag',
    'read_post' => 'read_etananyag',
    'delete_post' => 'delete_etananyag',
            'edit_posts' => 'edit_tananyags',
    'edit_others_posts' => 'edit_others_tananyags',
    'publish_posts' => 'publish_tananyags',
    'read_private_posts' => 'read_private_tananyags',
    'read' => 'read',
    'delete_posts' => 'delete_tananyags',
    'delete_private_posts' => 'delete_private_tananyags',
    'delete_published_posts' => 'delete_published_tananyags',
    'delete_others_posts' => 'delete_others_tananyags',
    'edit_private_posts'  => 'edit_private_tananyags',
    'edit_published_posts' => 'edit_published_tananyags',
    'create_posts' => 'edit_tananyags'
        ),
  'map_meta_cap' => true
);

register_post_type('tananyag', $args);

Creating the new role(almost same as author):

    add_role( 'e_tananyag', 'E-Tananyag', array(
    'upload_files' => 1,
    'read' => 1,
    'level_2' => 1,
    'level_1' => 1,
    'level_0' => 1,
  ));

Assigning the new role the custom capabilities:

    $tananyag_role = get_role('e_tananyag');
$tananyag_role->add_cap('edit_tananyags', true);
$tananyag_role->add_cap('delete_tananyags', true);
$tananyag_role->add_cap('edit_published_tananyags', true);
$tananyag_role->add_cap('publish_tananyags', true);
$tananyag_role->add_cap( 'delete_published_tananyags', true );
$tananyag_role->add_cap( 'read_etananyag', true );
$tananyag_role->add_cap( 'edit_etananyag', true );
$tananyag_role->add_cap( 'delete_etananyag', true );

Everything works fine, the user with the role etananyag can see, edit or modify the ctp, but he can't add featured image at all.

Please help

Registering the custom post type:

$labels = array(
  'name' => 'tananyags',
  'singular_name' => 'etananyag',
  'menu_name' => 'E-Tananyagok',
  'name_admin_bar' => 'Add new',
  'add_new' => 'Add New',
  'add_new_item' => 'Add New Item',
  'new_item' => 'New',
  'edit_item' => 'Edit',
  'view_item' => 'View Item',
  'all_items' => 'All',
  'search_items' => 'Search',
  'parent_item_colon' => 'Parent: ??',
  'not_found' => 'No item found',
  'not_found_in_trash' => 'No item found in the trash',
);

$args = array (
  'labels' => $labels,
  'public' => true,
  'publicly_quaryable' => true,
  'show_ui' => true,
  'show_in_menu' => true,
  'query_var' => false,
  'hierarchical'  => false,
  'capability_type'     => array('etananyag','tananyags'),
  'has_archive' => true,
  'menu_position' => 7,
  'rewrite' => array( 'slug' => 'etananyag'),
  'supports' => array( 'title', 'editor', 'thumbnail'),
  'taxonomies'  => array( 'category' ),
  'menu_icon' => 'dashicons-book-alt',
  'show_in_rest' => true,
  'capabilities' => array(
    'edit_post' => 'edit_etananyag',
    'read_post' => 'read_etananyag',
    'delete_post' => 'delete_etananyag',
            'edit_posts' => 'edit_tananyags',
    'edit_others_posts' => 'edit_others_tananyags',
    'publish_posts' => 'publish_tananyags',
    'read_private_posts' => 'read_private_tananyags',
    'read' => 'read',
    'delete_posts' => 'delete_tananyags',
    'delete_private_posts' => 'delete_private_tananyags',
    'delete_published_posts' => 'delete_published_tananyags',
    'delete_others_posts' => 'delete_others_tananyags',
    'edit_private_posts'  => 'edit_private_tananyags',
    'edit_published_posts' => 'edit_published_tananyags',
    'create_posts' => 'edit_tananyags'
        ),
  'map_meta_cap' => true
);

register_post_type('tananyag', $args);

Creating the new role(almost same as author):

    add_role( 'e_tananyag', 'E-Tananyag', array(
    'upload_files' => 1,
    'read' => 1,
    'level_2' => 1,
    'level_1' => 1,
    'level_0' => 1,
  ));

Assigning the new role the custom capabilities:

    $tananyag_role = get_role('e_tananyag');
$tananyag_role->add_cap('edit_tananyags', true);
$tananyag_role->add_cap('delete_tananyags', true);
$tananyag_role->add_cap('edit_published_tananyags', true);
$tananyag_role->add_cap('publish_tananyags', true);
$tananyag_role->add_cap( 'delete_published_tananyags', true );
$tananyag_role->add_cap( 'read_etananyag', true );
$tananyag_role->add_cap( 'edit_etananyag', true );
$tananyag_role->add_cap( 'delete_etananyag', true );

Everything works fine, the user with the role etananyag can see, edit or modify the ctp, but he can't add featured image at all.

Please help

Share Improve this question edited Mar 28, 2019 at 10:14 Pratik Patel 1,1111 gold badge11 silver badges23 bronze badges asked Mar 28, 2019 at 10:01 Sándor KerekesSándor Kerekes 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Found the Bug. On the custom post type, the guttenberg editor was activated by : 'show_in_rest' => true. This was blocking the featured image to show up. Removing the guttenberg fix the problem. With the classic editor the featured image is showing on the edit page.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745650280a4638222.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信