diff --git a/lib/compat/wordpress-6.1/block-template-utils.php b/lib/compat/wordpress-6.1/block-template-utils.php index 275bbbf18f276d..3a18f5930a5d8f 100644 --- a/lib/compat/wordpress-6.1/block-template-utils.php +++ b/lib/compat/wordpress-6.1/block-template-utils.php @@ -223,7 +223,42 @@ function gutenberg_get_block_template( $id, $template_type = 'wp_template' ) { $block_template->id = $id; $block_template->slug = $slug; $default_template_types = get_default_block_template_types(); - if ( array_key_exists( $slug, $default_template_types ) ) { + + $slug_parts = explode( '-', $slug, 3 ); + if ( count( $slug_parts ) > 1 ) { + if ( 'single' === $slug_parts [0] ) { + // Get CPT labels + $post_type = get_post_type_object( $slug_parts[1] ); + $labels = $post_type->labels; + + if ( count( $slug_parts ) > 2 ) { + // Now we look for the CPT with slug as defined in $slug_parts[2] + $post = get_page_by_path( $slug_parts[2], OBJECT, $slug_parts[1] ); + $block_template->title = sprintf( + // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type and %2$s is the name of the post, e.g. "Post: Hello, WordPress" + __( '%1$s: %2$s' ), + $labels->singular_name, + $post->post_title + ); + $block_template->description = sprintf( + // translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Post: Hello, WordPress" + __( 'Template for %1$s' ), + $block_template->title + ); + } else { + $block_template->title = sprintf( + // translators: %s: Name of the post type e.g: "Post". + __( 'Single item: %s' ), + $labels->singular_name + ); + $block_template->description = sprintf( + // translators: %s: Name of the post type e.g: "Post". + __( 'Displays a single item: %s.' ), + $labels->singular_name + ); + } + } + } elseif ( array_key_exists( $slug, $default_template_types ) ) { $block_template->title = $default_template_types[ $slug ]['title']; $block_template->description = $default_template_types[ $slug ]['description']; }