WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.17k stars 4.05k forks source link

Custom Roles with ONLY Custom Post Type Capabilities Hangs Editor #28071

Closed metalandcoffee closed 3 years ago

metalandcoffee commented 3 years ago

Describe the bug When defining a custom post type and defining a custom user role with capabilities for that post type, Gutenberg editor hangs...

I am on WordPress 5.6. When I add the 'edit_posts' capability, the Gutenberg editor works fine. But this is not ideal since I only want the custom role to access this specific post type.

This worked fine on WordPress 5.5.3.

Here is the code I used to create the conditional.

add_action( 'init', 'yks_register_kittens' );
function yks_register_kittens() {

    $names = array(
        'name'          => 'Kittens',
        'singular_name' => 'Kitten',
    );

    $args = array(
        'labels'              => $names,
        'description'         => 'Add Kittens for Adoption',
        'public'              => true,
        'hierarchical'        => false,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_icon'           => 'dashicons-pets',
        'capability_type'     => 'kitten',
        'map_meta_cap'        => true,
        'query_var'           => true,
        'has_archive'         => true,
        'supports'            => array( 'title', 'editor' ),
        'show_in_rest'        => true,
    );

    register_post_type( 'yks-test-kittens', $args );
}

add_action( 'init', 'yks_add_kitten_manager_role' );
function yks_add_kitten_manager_role() {
    add_role(
        'kitten_manager',
        'Kitten Manager',
        array(
            'read'                 => true,
            'edit_kitten'          => true,
            'read_kitten'          => true,
            'delete_kitten'        => true,
            'edit_kittens'         => true,
            'edit_others_kittens'  => true,
            'publish_kittens'      => true,
            'read_private_kittens' => true,
            'create_kittens'       => true,
        )
    );
}

To reproduce Steps to reproduce the behavior:

  1. Add above code to create a custom post type and custom user role
  2. Create new user with custom user role.
  3. Login as new user with custom user role.
  4. Create a new post for the custom post type.

Expected behavior Gutenberg editor is functional.

Screenshots image

https://user-images.githubusercontent.com/20868511/104102800-9da95d00-526c-11eb-93ec-8254e6c64de2.mov

Editor version (please complete the following information):

Desktop (please complete the following information):

skorasaurus commented 3 years ago

Hi,

Thanks for reporting and also for including the screenshots and detailed code to reproduce this. This has been reported at #27854 and I'll reply more to your comment there.