Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ihdk opened this issue Jul 14, 2021 · 3 comments
Labels
[Feature] Template Editing Mode Related to the template editor available in the Block Editor Needs Testing Needs further testing to be confirmed.

Comments

@ihdk
Copy link

ihdk commented Jul 14, 2021

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.

@Mamaduka Mamaduka added [Feature] Template Editing Mode Related to the template editor available in the Block Editor Needs Testing Needs further testing to be confirmed. labels Jul 15, 2021
@ihdk
Copy link
Author

ihdk commented Jul 16, 2021

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
Copy link

Azragh commented Jul 23, 2021

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Template Editing Mode Related to the template editor available in the Block Editor Needs Testing Needs further testing to be confirmed.
Projects
None yet
Development

No branches or pull requests

3 participants