Gutenberg: Feature Image disappears only in Gutenberg with CPT

Created on 21 Nov 2018  路  14Comments  路  Source: WordPress/gutenberg

I'm starting to test Gutenberg (4.5.1) in some clients web apps and this is a strange behavior:
I have 2 CPT ("Projects" and "News") and I'm not using the default "Posts" type (DPT).

I have created some User Roles in "Members" plugin with access to the 2 CPT only. They have "Edit Posts" disabled only in the DPT.

All working well but Featured image disappears (in Classic editor is ok). But It comes back on when you enable "Edit Posts" in the DPT type for those Roles.

I've tried turning on/off everything (I hope) in register_post_type() but never worked.
I only have these: 'supports' => array('title', 'thumbnail', 'editor', 'excerpt')

Desktop (please complete the following information):

  • Windows
  • Chrome, Firefox, Opera
  • Latest

I hope it helps.

Needs Technical Feedback [Feature] Document Settings [Feature] Extensibility [Type] Bug

Most helpful comment

All 14 comments

Same here. I have an event custom post type registered with the following arguments:

'capability_type' => array('event','events'),
'capabilities'    => array(
    'read'                  => 'read_events',
    'read_private_posts'    => 'read_private_events',
    'edit'                  => 'edit_events',
    'edit_private_posts'    => 'edit_private_events',
    'edit_published_posts'  => 'edit_published_events',
    'edit_others_posts'     => 'edit_others_events',
    'publish'               => 'publish_events',
    'delete'                => 'delete_events',
    'delete_private_post'   => 'delete_private_events',
    'delete_published_post' => 'delete_published_events',
    'delete_others_post'    => 'delete_others_events',
),
'map_meta_cap'    => true,

and a custom role which has the following capabilities :

  • read_events
  • read_private_events
  • edit_events
  • edit_private_events
  • edit_published_events
  • publish_events
  • delete_events
  • delete_private_events
  • delete_published_events

When I'm logged in as an administrator, I can edit the Featured Image in Gutenberg, but when I have the custom role, I can't.

When I disable Gutenberg using the Classic Editor plugin, I can edit the Featured Image with the custom role.

As mentionned, when I add edit_posts capability to this role, I can edit the Featured Image, but also other post types like posts (unwanted).

Tested with WP 5.0.3.

@designsimply Could you give a look at that? It looks like a bug.

@ridesirat, I installed and activated the Members 2.10 plugin, but I'm still not quite sure how to do this part:

I have created some User Roles in "Members" plugin with access to the 2 CPT only.

I installed & activated Jetpack 6.9 and Confit 1.3.3, but when I went to Users > Roles and created a new role I wasn't sure how to give access to just the CPTs (Confit+Jetpack has two CPTs: Testimonials & Food Menus). Would you mind walking me through testing steps for that part in a bit more detail?

@benoitchantre I'll update the labels! I also did a quick search on core.trac and found a very similar (but very old!) ticket about featured images not working with CPTs and am adding a link to it here just in case it's helpful https://core.trac.wordpress.org/ticket/15779 (apologies if it's too old or too different to be useful). However, based on reading that issue and also noting that a similar issue was reported at https://github.com/WordPress/gutenberg/issues/6919 and turned out to be a plugin conflict and not an issue with Gutenberg in that case. In 6919, they mention that updating to ACF Pro 5.6.10 fixed the issue and I tried checking the ACF plugin changelog for anything related but didn't spot anything.

Same here. The Featured Image for CPT does not appear if the user has not the edit_posts capability.

Hi
I was making some more tests with the new version (5.0.3) and now, if edit_posts is off, the page to edit doesn't even open for the User with the specific Role.
This is the option it has to be on for the thumbnails (now full page) to appear:
editcap_posts

@designsimply I don't know if your CPTs are showing. In order to show in "Edit Role" on the "Members" plugin I have 'capability_type' => 'destaques' in `register_post_type``. (Destaques = News in my case)
editcap_news

I now came with a workaround for my problem: Leave edit_posts in the DPT (Default Posts Type) active and hide "Posts" on the Admin Menu:
// EXP 2 function remove_menus() { remove_menu_page('edit.php'); // Posts }
I don't know if it is problematic but it seems to be working. Going to test some more. Some advise on this one?
Thank you.

I have the same issue as described by @benoitchantre and @ridesirat. I have a custom post type (cities) with custom capabilities. I also have a custom role (city_manager) which has all of my CPT's caps (edit_cities, publish_cities, etc.) and upload_files.

As an admin, using Gutenberg (WP5.0.3 and/or plugin), I can see the featured image for my Cities CPT.

As a city_manager, using Gutenberg, the featured image metabox does not appear.

When I check off the edit_posts cap (using the User Role Editor) or activate the Classic Editor plugin, the metabox appears for my City Manager.

The only plugins I have on the site are Classic Editor, Gutenberg, User Role Editor, and the WordPress Importer. I've also switched to the twentynineteen theme and can confirm the issue is still there.

@benoitchantre I'm a little bit out of my depth, I wasn't sure how to add your example, but I found https://codex.wordpress.org/Function_Reference/register_post_type#Example and added the elaborate example from there (and also 'show_in_rest' => true,) but I had some trouble when creating a custom role and getting any kind of post, including the custom post type, without edit_posts being set (this is surely because I'm not clear yet on how to properly add a custom role the right way).

I also noticed that nothing in the example from https://codex.wordpress.org/Function_Reference/register_post_type#Example didn't work if I added 'capability_type' => array('book','books'), similar to what you have but it did work if I added 'capability_type' => 'post', together with edit_posts for the custom role.

When I'm logged in as an administrator, I can edit the Featured Image in Gutenberg, but when I have the custom role, I can't.

I noticed that you didn't have upload_files in the capabilities list for your custom role for your events post type and I was wondering if that's intentional because your end goal is to allow the custom role to modify the featured image but you do not want to give them the capability to upload new featured images. Just wanting to get a check on that for clarification.

@designsimply Sorry if my first comment didn't contained enough details. Here's something more detailed. You can create a file with the following code and place it in a mu-plugins directory (if you don't have one, you can create this directory in wp-content.

cpt-capabilities-test.php

<?php
/*
Plugin Name: Custom Post Type - capabalities test
Description: Register an event custom post type with custom capabilities
*/

function cpt_capabilities_test_register_post_type() {
    $labels = array(
        'name'                  => 'Events',
        'singular_name'         => 'Event',
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'show_in_rest' => true,
        'capability_type' => array('event','events'),
        'capabilities'    => array(
            'read'                  => 'read_events',
            'read_private_posts'    => 'read_private_events',
            'edit'                  => 'edit_events',
            'edit_private_posts'    => 'edit_private_events',
            'edit_published_posts'  => 'edit_published_events',
            'edit_others_posts'     => 'edit_others_events',
            'publish'               => 'publish_events',
            'delete'                => 'delete_events',
            'delete_private_post'   => 'delete_private_events',
            'delete_published_post' => 'delete_published_events',
            'delete_others_post'    => 'delete_others_events',
        ),
        'map_meta_cap'    => true,
        'supports'        => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
    );

    register_post_type( 'event', $args );
}
add_action( 'init', 'cpt_capabilities_test_register_post_type' );

This will register a custom post type with the custom capabilities. As your user/role don't have these capabilities, nothing will show in your dashboard until you add them. To add them without code, I suggest you to use the Members plugin. When activated, you will be able to edit the capabilities under Users > Roles.

To fully test the issue, you'll need a test user and a custom role.
Under Users > Roles, add a new role with all event capabilities, plus _Read_ (General) and _Upload Files_.

When logged in with you test user using this custom role, you should see the Event post type in the dashboard. You should also be able to create events and see that:

  1. you can see the post thumbnails metabox and upload pictures when Classic Editor is turned on (or simply change show_in_rest value to false)
  2. you cannot see the post thumbnails metabox with the Block editor

Now, if you check the _Edit Posts_ capability, you'll see that the post thumbnails metabox reappears in the Block editor. You also get the ability to create posts (unwanted).

The User Switching plugin will help you to quickly change the current user account.

I hope it helps.

I noticed that you didn't have upload_files in the capabilities list for your custom role for your events post type and I was wondering if that's intentional because your end goal is to allow the custom role to modify the featured image but you do not want to give them the capability to upload new featured images. Just wanting to get a check on that for clarification.

The upload_files capability was set in my custom role. I forgot to mention it.

The upload_files capability was set in my custom role. I forgot to mention it.

Gah. I thought I was onto something there! 馃榿 I will try this test again soon using the extra details! Thanks for walking me through. 馃檪

I run into exactly the same problem as described by @benoitchantre. Unless the edit_posts cap is added to the role, the featured image panel does not appear.

I am having a same problem.
I developed a example plugin to reproduce this problem.
https://github.com/miya0001/reproduce-12198

I found the cause of this problem.

<ThemeSupportCheck> is checking that the theme supports post-thumbnail via REST-API.
But the REST-API needs edit_posts capability. So <ThemeSupportCheck> always returns false if user doesn't have this capability.

https://github.com/WordPress/WordPress/blob/c41dede996bbb50055f914d9094be59f659a4d14/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php#L60-L66

In this issue, we created a custom capability like edit_events not edit_posts.
It should be checked with mapped capability.

I opened a ticket on Trac.
https://core.trac.wordpress.org/ticket/46723

If I'm understanding correctly, as the issue stems from the REST API implementation, Trac is the correct place to follow this issue, and it would immediately become resolved in Gutenberg as a result of a fix there (i.e. it is implemented correctly in Gutenberg).

Thanks for debugging and following-up with the Trac ticket.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronjorbin picture aaronjorbin  路  3Comments

pfefferle picture pfefferle  路  3Comments

davidsword picture davidsword  路  3Comments

maddisondesigns picture maddisondesigns  路  3Comments

mhenrylucero picture mhenrylucero  路  3Comments