Replace LYS coming soon override to use template include filter and handle 404 gracefully (#46667)
* Hide woo breadcrumb * Update coming soon entire site style * Update style * Fix wp group block * Change coming soon template to use template_include instead * Changelog * Change to add_filter * Proper handling for non-FSE themes * Update comments --------- Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
This commit is contained in:
parent
b9ea5bacd8
commit
ecb48cc0fb
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: update
|
||||||
|
|
||||||
|
Update to use template_include instead, handle 404 for restrict store pages only
|
|
@ -25,7 +25,7 @@ class ComingSoonRequestHandler {
|
||||||
*/
|
*/
|
||||||
final public function init( ComingSoonHelper $coming_soon_helper ) {
|
final public function init( ComingSoonHelper $coming_soon_helper ) {
|
||||||
$this->coming_soon_helper = $coming_soon_helper;
|
$this->coming_soon_helper = $coming_soon_helper;
|
||||||
add_action( 'parse_request', array( $this, 'handle_parse_request' ) );
|
add_filter( 'template_include', array( $this, 'handle_template_include' ) );
|
||||||
add_action( 'wp_enqueue_scripts', array( $this, 'deregister_unnecessary_styles' ), 100 );
|
add_action( 'wp_enqueue_scripts', array( $this, 'deregister_unnecessary_styles' ), 100 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,35 +57,49 @@ class ComingSoonRequestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the current request and sets the page ID to the coming soon page if it
|
* Replaces the page template with a 'coming soon' when the site is in coming soon mode.
|
||||||
* needs to be shown in place of the normal page.
|
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*
|
*
|
||||||
* @param \WP $wp Current WordPress environment instance (passed by reference).
|
* @param string $template The path to the previously determined template.
|
||||||
|
* @return string|null The path to the 'coming soon' template or null to prevent further template loading in FSE themes.
|
||||||
*/
|
*/
|
||||||
public function handle_parse_request( \WP &$wp ) {
|
public function handle_template_include( $template ) {
|
||||||
|
global $wp;
|
||||||
|
|
||||||
if ( ! $this->should_show_coming_soon( $wp ) ) {
|
if ( ! $this->should_show_coming_soon( $wp ) ) {
|
||||||
return $wp;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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();
|
||||||
|
|
||||||
|
// Optimize search engine by returning 503 status code and set retry-after header to 12 hours.
|
||||||
|
status_header( 503 );
|
||||||
|
header( 'Retry-After: ' . 12 * HOUR_IN_SECONDS );
|
||||||
|
|
||||||
add_theme_support( 'block-templates' );
|
add_theme_support( 'block-templates' );
|
||||||
wp_dequeue_style( 'global-styles' );
|
wp_dequeue_style( 'global-styles' );
|
||||||
$template = get_query_template( 'coming-soon' );
|
$coming_soon_template = get_query_template( 'coming-soon' );
|
||||||
|
|
||||||
if ( ! wc_current_theme_is_fse_theme() && $this->coming_soon_helper->is_store_coming_soon() ) {
|
if ( ! wc_current_theme_is_fse_theme() && $this->coming_soon_helper->is_store_coming_soon() ) {
|
||||||
get_header();
|
get_header();
|
||||||
}
|
}
|
||||||
|
|
||||||
include $template;
|
include $coming_soon_template;
|
||||||
|
|
||||||
if ( ! wc_current_theme_is_fse_theme() && $this->coming_soon_helper->is_store_coming_soon() ) {
|
if ( ! wc_current_theme_is_fse_theme() && $this->coming_soon_helper->is_store_coming_soon() ) {
|
||||||
get_footer();
|
get_footer();
|
||||||
}
|
}
|
||||||
|
|
||||||
die();
|
if ( wc_current_theme_is_fse_theme() ) {
|
||||||
|
// Since we've already rendered a template, return null to ensure no other template is rendered.
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
// In non-FSE themes, other templates will still be rendered.
|
||||||
|
// We need to exit to prevent further processing.
|
||||||
|
exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,6 +120,11 @@ class ComingSoonRequestHandler {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not show coming soon on 404 pages when restrict to store pages only.
|
||||||
|
if ( $this->coming_soon_helper->is_store_coming_soon() && is_404() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Early exit if the URL doesn't need a coming soon screen.
|
// Early exit if the URL doesn't need a coming soon screen.
|
||||||
$url = $this->coming_soon_helper->get_url_from_wp( $wp );
|
$url = $this->coming_soon_helper->get_url_from_wp( $wp );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue