From c1ef71740c8193dd2973e714e0cb61ea58a32885 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 6 Dec 2021 14:06:55 +0100 Subject: [PATCH 1/2] Move the template loader code to lib/compat/5.9 --- .../wordpress-5.9/block-template.php} | 20 ++++++++----------- .../wordpress-5.9}/template-canvas.php | 0 lib/load.php | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) rename lib/{full-site-editing/template-loader.php => compat/wordpress-5.9/block-template.php} (96%) rename lib/{ => compat/wordpress-5.9}/template-canvas.php (100%) diff --git a/lib/full-site-editing/template-loader.php b/lib/compat/wordpress-5.9/block-template.php similarity index 96% rename from lib/full-site-editing/template-loader.php rename to lib/compat/wordpress-5.9/block-template.php index 5077d02472491..85b0a91b4ed04 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/compat/wordpress-5.9/block-template.php @@ -17,7 +17,7 @@ function gutenberg_add_template_loader_filters() { if ( 'embed' === $template_type ) { // Skip 'embed' for now because it is not a regular template type. continue; } - add_filter( str_replace( '-', '', $template_type ) . '_template', 'gutenberg_override_query_template', 20, 3 ); + add_filter( str_replace( '-', '', $template_type ) . '_template', 'gutenberg_locate_block_template', 20, 3 ); } // Request to resolve a template. @@ -38,7 +38,7 @@ function gutenberg_add_template_loader_filters() { * @param array $templates A list of template candidates, in descending order of priority. * @return string The path to the Full Site Editing template canvas file. */ -function gutenberg_override_query_template( $template, $type, array $templates ) { +function gutenberg_locate_block_template( $template, $type, array $templates ) { global $_wp_current_template_content; if ( $template ) { @@ -97,6 +97,7 @@ function gutenberg_override_query_template( $template, $type, array $templates ) // Render title tag with content, regardless of whether theme has title-tag support. remove_action( 'wp_head', '_wp_render_title_tag', 1 ); // Remove conditional title tag rendering... + // Override WP 5.8 title-tag support. remove_action( 'wp_head', '_block_template_render_title_tag', 1 ); add_action( 'wp_head', 'gutenberg_render_title_tag', 1 ); // ...and make it unconditional. @@ -126,7 +127,7 @@ function gutenberg_resolve_template( $template_type, $template_hierarchy, $fallb } $slugs = array_map( - 'gutenberg_strip_php_suffix', + 'gutenberg_strip_template_file_suffix', $template_hierarchy ); @@ -223,13 +224,6 @@ function gutenberg_get_the_template_html() { return '
' . $content . '
'; } -/** - * Renders the markup for the current template. - */ -function gutenberg_render_the_template() { - echo gutenberg_get_the_template_html(); // phpcs:ignore WordPress.Security.EscapeOutput -} - /** * Renders a 'viewport' meta tag. * @@ -247,7 +241,7 @@ function gutenberg_viewport_meta_tag() { * @param string $template_file Template file name. * @return string Template file name without extension. */ -function gutenberg_strip_php_suffix( $template_file ) { +function gutenberg_strip_template_file_suffix( $template_file ) { return preg_replace( '/\.(php|html)$/', '', $template_file ); } @@ -274,8 +268,10 @@ function gutenberg_template_render_without_post_block_context( $context ) { return $context; } -add_filter( 'render_block_context', 'gutenberg_template_render_without_post_block_context' ); +// override WordPress 5.8 filters. +remove_filter( 'render_block_context', '_block_template_render_without_post_block_context' ); +add_filter( 'render_block_context', 'gutenberg_template_render_without_post_block_context' ); /** * Sets the current WP_Query to return auto-draft posts. diff --git a/lib/template-canvas.php b/lib/compat/wordpress-5.9/template-canvas.php similarity index 100% rename from lib/template-canvas.php rename to lib/compat/wordpress-5.9/template-canvas.php diff --git a/lib/load.php b/lib/load.php index 4bb1884c36873..fd58ad1166af6 100644 --- a/lib/load.php +++ b/lib/load.php @@ -109,8 +109,8 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php'; require __DIR__ . '/compat/wordpress-5.9/class-wp-theme-json-resolver-gutenberg.php'; require __DIR__ . '/full-site-editing/full-site-editing.php'; -require __DIR__ . '/full-site-editing/template-loader.php'; require __DIR__ . '/full-site-editing/edit-site-page.php'; +require __DIR__ . '/compat/wordpress-5.9/block-template.php'; require __DIR__ . '/compat/wordpress-5.9/wp-theme-get-post-templates.php'; require __DIR__ . '/compat/wordpress-5.9/default-theme-supports.php'; require __DIR__ . '/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php'; From 2d561715813e09b953ef6b784023562087acba23 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 7 Dec 2021 10:06:36 +0100 Subject: [PATCH 2/2] Fix template file link --- lib/compat/wordpress-5.9/block-template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/block-template.php b/lib/compat/wordpress-5.9/block-template.php index 85b0a91b4ed04..4a57ece0d8c1f 100644 --- a/lib/compat/wordpress-5.9/block-template.php +++ b/lib/compat/wordpress-5.9/block-template.php @@ -102,7 +102,7 @@ function gutenberg_locate_block_template( $template, $type, array $templates ) { add_action( 'wp_head', 'gutenberg_render_title_tag', 1 ); // ...and make it unconditional. // This file will be included instead of the theme's template file. - return gutenberg_dir_path() . 'lib/template-canvas.php'; + return gutenberg_dir_path() . 'lib/compat/wordpress-5.9/template-canvas.php'; } /**