From e54b597f66c358eaaa1fbfb585db901bc741789b Mon Sep 17 00:00:00 2001 From: Miguel Fonseca Date: Mon, 14 Sep 2020 19:48:35 +0100 Subject: [PATCH] try a rendering script --- lib/edit-site-export.php | 4 ++-- lib/full-site-editing.php | 2 +- lib/render-script.php | 10 ++++++++ lib/templates-sync.php | 23 ++++++++++++++----- lib/templates.php | 19 --------------- .../block-library/src/template-part/index.php | 4 ++-- 6 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 lib/render-script.php diff --git a/lib/edit-site-export.php b/lib/edit-site-export.php index 14c0a756c57b3a..6fffe2e048bbc8 100644 --- a/lib/edit-site-export.php +++ b/lib/edit-site-export.php @@ -44,7 +44,7 @@ function gutenberg_edit_site_export() { while ( $template_query->have_posts() ) { $template = $template_query->next_post(); $zip->addFromString( - 'theme/block-templates/' . $template->post_name . '.html', + 'theme/block-templates/' . $template->post_name . '.php', gutenberg_strip_post_ids_from_template_part_blocks( $template->post_content ) ); } @@ -68,7 +68,7 @@ function gutenberg_edit_site_export() { while ( $template_part_query->have_posts() ) { $template_part = $template_part_query->next_post(); $zip->addFromString( - 'theme/block-template-parts/' . $template_part->post_name . '.html', + 'theme/block-template-parts/' . $template_part->post_name . '.php', gutenberg_strip_post_ids_from_template_part_blocks( $template_part->post_content ) ); } diff --git a/lib/full-site-editing.php b/lib/full-site-editing.php index 059b39ccb971f0..8de9869dca73a7 100644 --- a/lib/full-site-editing.php +++ b/lib/full-site-editing.php @@ -11,7 +11,7 @@ * @return boolean Whether the current theme is an FSE theme or not. */ function gutenberg_is_fse_theme() { - return is_readable( get_stylesheet_directory() . '/block-templates/index.html' ); + return is_readable( get_stylesheet_directory() . '/block-templates/index.php' ); } /** diff --git a/lib/render-script.php b/lib/render-script.php new file mode 100644 index 00000000000000..752bc633fe9275 --- /dev/null +++ b/lib/render-script.php @@ -0,0 +1,10 @@ + $file ) { $path_list[] = $path; } @@ -134,14 +146,13 @@ function _gutenberg_synchronize_theme_templates( $template_type ) { $path = $template_file['path']; $theme = $template_file['theme']; $template_base_path = $template_base_paths[ $template_type ]; - - $content = file_get_contents( $path ); - $slug = substr( + $content = _gutenberg_read_template( $path ); + $slug = substr( $path, // Starting position of slug. strpos( $path, $template_base_path . DIRECTORY_SEPARATOR ) + 1 + strlen( $template_base_path ), - // Subtract ending '.html'. - -5 + // Subtract ending '.php'. + -4 ); _gutenberg_create_auto_draft_for_template( $template_post_types[ $template_type ], $slug, $theme, $content ); } diff --git a/lib/templates.php b/lib/templates.php index aa085c0d54d125..9f0be1c3317121 100644 --- a/lib/templates.php +++ b/lib/templates.php @@ -5,25 +5,6 @@ * @package gutenberg */ -/** - * Returns all block template file path of the current theme and its parent theme. - * Includes demo block template files if demo experiment is enabled. - * - * @return array $block_template_files A list of paths to all template files. - */ -function gutenberg_get_template_paths() { - $block_template_files = glob( get_stylesheet_directory() . '/block-templates/*.html' ); - $block_template_files = is_array( $block_template_files ) ? $block_template_files : array(); - - if ( is_child_theme() ) { - $child_block_template_files = glob( get_template_directory() . '/block-templates/*.html' ); - $child_block_template_files = is_array( $child_block_template_files ) ? $child_block_template_files : array(); - $block_template_files = array_merge( $block_template_files, $child_block_template_files ); - } - - return $block_template_files; -} - /** * Registers block editor 'wp_template' post type. */ diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index c19f23c7bd546b..c1c8fb8fe0afff 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -44,9 +44,9 @@ function render_block_core_template_part( $attributes ) { } else { // Else, if the template part was provided by the active theme, // render the corresponding file content. - $template_part_file_path = get_stylesheet_directory() . '/block-template-parts/' . $attributes['slug'] . '.html'; + $template_part_file_path = get_stylesheet_directory() . '/block-template-parts/' . $attributes['slug'] . '.php'; if ( 0 === validate_file( $template_part_file_path ) && file_exists( $template_part_file_path ) ) { - $content = file_get_contents( $template_part_file_path ); + $content = _gutenberg_read_template( $template_part_file_path ); } } }