From c80e8bb4ecb267b80a28d5e5b721b4eae97bdd54 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Tue, 25 Feb 2020 06:24:22 -0800 Subject: [PATCH] Template Loader: Get current template correctly for auto drafting template parts in the editor. --- lib/template-loader.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/template-loader.php b/lib/template-loader.php index 174a093b6f6a80..c5463f9a3f1440 100644 --- a/lib/template-loader.php +++ b/lib/template-loader.php @@ -304,12 +304,16 @@ function gutenberg_strip_php_suffix( $template_file ) { * @return array Filtered editor settings. */ function gutenberg_template_loader_filter_block_editor_settings( $settings ) { + global $_wp_current_template_id; if ( ! post_type_exists( 'wp_template' ) || ! post_type_exists( 'wp_template_part' ) ) { return $settings; } // Create template part auto-drafts for the edited post. - foreach ( parse_blocks( get_post()->post_content ) as $block ) { + $post = isset( $_wp_current_template_id ) + ? get_post( $_wp_current_template_id ) // It's a template. + : get_post(); // It's a post. + foreach ( parse_blocks( $post->post_content ) as $block ) { create_auto_draft_for_template_part_block( $block ); }