Fix coming soon page fatal error with non-FSE theme (#46570)

* Fix fatal error with non-fse theme

* Update conditional inclusion of header and footer templates in coming-soon-store-only.php

* Update conditional inclusion of header and footer templates in ComingSoonRequestHandler.php

* Remove add_theme_support( block-template-parts );

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chi-Hsuan Huang 2024-04-15 12:26:18 +08:00 committed by GitHub
parent fcfec4000e
commit 9a288fb4c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 5 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix coming soon page fatal error with non-FSE theme

View File

@ -9,7 +9,12 @@
?> ?>
<!-- wp:template-part {"slug":"header","tagName":"header"} /--> <?php
if ( wc_current_theme_is_fse_theme() ) {
echo '<!-- wp:template-part {"slug":"header","tagName":"header"} /-->';
}
?>
<!-- wp:group {"layout":{"type":"constrained"}} --> <!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:spacer --> <div class="wp-block-group"><!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div> <div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
@ -31,5 +36,10 @@
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div> <div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div> <!-- /wp:spacer --></div>
<!-- /wp:group --> <!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->
<?php
if ( wc_current_theme_is_fse_theme() ) {
echo '<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->';
}
?>

View File

@ -3,6 +3,7 @@ namespace Automattic\WooCommerce\Blocks;
use Automattic\WooCommerce\Blocks\Templates\ProductCatalogTemplate; use Automattic\WooCommerce\Blocks\Templates\ProductCatalogTemplate;
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils; use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
use Automattic\WooCommerce\Blocks\Templates\ComingSoonTemplate;
/** /**
* BlockTypesController class. * BlockTypesController class.
@ -331,12 +332,13 @@ class BlockTemplatesController {
* @return array * @return array
*/ */
public function add_block_templates( $query_result, $query, $template_type ) { public function add_block_templates( $query_result, $query, $template_type ) {
if ( ! BlockTemplateUtils::supports_block_templates( $template_type ) ) { $slugs = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
if ( ! BlockTemplateUtils::supports_block_templates( $template_type ) && ! in_array( ComingSoonTemplate::SLUG, $slugs, true ) ) {
return $query_result; return $query_result;
} }
$post_type = isset( $query['post_type'] ) ? $query['post_type'] : ''; $post_type = isset( $query['post_type'] ) ? $query['post_type'] : '';
$slugs = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
$template_files = $this->get_block_templates( $slugs, $template_type ); $template_files = $this->get_block_templates( $slugs, $template_type );
$theme_slug = wp_get_theme()->get_stylesheet(); $theme_slug = wp_get_theme()->get_stylesheet();

View File

@ -53,7 +53,9 @@ class BlockTemplatesRegistry {
SingleProductTemplate::SLUG => new SingleProductTemplate(), SingleProductTemplate::SLUG => new SingleProductTemplate(),
); );
} else { } else {
$templates = array(); $templates = array(
ComingSoonTemplate::SLUG => new ComingSoonTemplate(),
);
} }
if ( BlockTemplateUtils::supports_block_templates( 'wp_template_part' ) ) { if ( BlockTemplateUtils::supports_block_templates( 'wp_template_part' ) ) {
$template_parts = array( $template_parts = array(

View File

@ -66,10 +66,20 @@ class ComingSoonRequestHandler {
// A coming soon page needs to be displayed. Don't cache this response. // A coming soon page needs to be displayed. Don't cache this response.
nocache_headers(); nocache_headers();
add_theme_support( 'block-templates' );
$template = get_query_template( 'coming-soon' ); $template = get_query_template( 'coming-soon' );
if ( ! wc_current_theme_is_fse_theme() && $this->coming_soon_helper->is_store_coming_soon() ) {
get_header();
}
include $template; include $template;
if ( ! wc_current_theme_is_fse_theme() && $this->coming_soon_helper->is_store_coming_soon() ) {
get_footer();
}
die(); die();
} }
} }