WordPress / gutenberg

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

Missing Template selection in editor on Custom Post Type edit page, after update to 5.8-RC3 #33427

Closed ihdk closed 3 years ago

ihdk commented 3 years ago

Description

Hello, I'm using Custom Post Type with custom Templates. Available templates are available on this custom post edit page with WP 5.7.2. After update to WP 5.8-RC3 I can see that Templates selection was moved from Page Attributes tab to Template tab in editor screen while I am editing standard Page. But on my custom post type edit screen there is totally missing Template tab to select from available templates.

Custom Templates for my Custom Post Type are added using theme_{$post_type}_templates filter, exactly following instruction in https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/ what worked perfectly until update to WP 5.8

Thanks for any response...

Step-by-step reproduction instructions

  1. create custom templates for custom post type using theme_{$post_type}_templates filter with latest public WP version
  2. update to WP 5.8
  3. on edit page of custom post type there is no way to select created templates

Expected behaviour

After update to WP5.8 there would be Template selection on Custom Post Type edit page like it's still available on edit page of standard Page.

ihdk commented 3 years ago

Hello, after further investigation I found that templates selection is missing in wp5.8 if my custom post type is registered with public parameter set to false. Once the public parameter is defined as true I can select the template.

Is it really wanted behavior in WP 5.8 ?

To make sure it has nothing to do with my other custom codes, I've tested it with TwentytwentyOne theme, with following code in functions.php

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

    register_post_type( 'my-cpt', [
        'labels'                => [
            'name'                     => esc_html_x( 'My CPTs', 'post type general name', 'textdomain' ),
            'singular_name'            => esc_html_x( 'My CPT', 'post type singular name', 'textdomain' ),
            'menu_name'                => esc_html_x( 'My CPTs', 'admin menu', 'textdomain' ),
            'edit_item'                => esc_html__( 'Edit My CPT', 'textdomain' ),
            'all_items'                => esc_html__( 'All My CPTs', 'textdomain' ),
            'search_items'             => esc_html__( 'Search Special ages', 'textdomain' ),
            'not_found'                => esc_html__( 'No My CPTs found.', 'textdomain' ),
            'filter_items_list'        => esc_html__( 'Filter My CPTs list', 'textdomain' ),
            'items_list_navigation'    => esc_html__( 'My CPTs list navigation', 'textdomain' ),
            'items_list'               => esc_html__( 'My CPTs list', 'textdomain' ),
            'item_updated'             => esc_html__( 'My CPT updated.', 'textdomain' ),
        ],
        'public'                => false,
        'show_ui'               => true,
        'show_in_menu'          => false,
        'rewrite'               => false,
        'show_in_rest'          => true,

        'capabilities' => [
            'read_private_posts' => 'read_private_my_cpts',
            'read_post' => 'read_my_cpt',
            'publish_posts' => 'publish_my_cpts',
            'edit_post' => 'edit_my_cpt',
            'edit_posts' => 'edit_my_cpts',
            'create_posts' => 'create_my_cpts',
            'delete_posts' => 'delete_my_cpts',
        ],

        'supports' => [
            'title',
            'editor',
            'custom-fields',
        ],
    ] );

    $role = get_role( 'administrator' );

    foreach ( [
        'read_private_my_cpts',
        'read_my_cpt',
        'publish_my_cpts',
        'edit_my_cpt',
        'edit_my_cpts',
        'create_my_cpts',
        'delete_my_cpts'
    ] as $cap ) {
        $role->add_cap( $cap );
    }
}

add_filter( 'theme_my-cpt_templates', 'theme_my_cpt_templates' );
function theme_my_cpt_templates( $templates ){
    $templates["page-templates/template-first.php"] = __( 'First template', 'textdomain');
    $templates["page-templates/template-second.php"] = __( 'Second template', 'textdomain');
    return $templates;
}

Thanks for your help.

Azragh commented 3 years ago

Im missing the template selection even on normal pages ..

image

I only have a page.php and page-fullwidth.php (marked correctly with Template Name:) in my themes, no custom post types or anything special.

Mamaduka commented 3 years ago

Hello, @ihdk

We tested this issue during a triage session today.

While we were able to reproduce the issue, it looks like to be the expected behavior. If you can't publicly access the post type, there's no need for the front-end template. Setting public to false means that the post type isn't publicly accessible.

@Azragh Recently, "Templates" were moved into their panel and should be available at the very top of the sidebar.

CleanShot 2021-09-28 at 09 56 05