From a796797e70f73b0c7ffecb4682a9c4d9840dedf5 Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Fri, 13 Nov 2026 20:22:49 -0400 Subject: [PATCH] fix: keep the static site header and footer off the account and payment pages Signed-off-by: YvesCesar --- inc/footer-fragment.php | 11 ++++-- tests/Integration/Inc/FooterFragmentTest.php | 35 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/inc/footer-fragment.php b/inc/footer-fragment.php index c93a3c8..c2b464b 100644 --- a/inc/footer-fragment.php +++ b/inc/footer-fragment.php @@ -422,13 +422,20 @@ function libresign_theme_site_fragment_load_artifact( $fragment_type ) { return null; } +function libresign_theme_site_fragment_is_excluded_page() { + return ( function_exists( 'is_checkout' ) && is_checkout() ) + || ( function_exists( 'is_order_received_page' ) && is_order_received_page() ) + || ( function_exists( 'is_account_page' ) && is_account_page() ) + || libresign_theme_is_direct_lost_password_route(); +} + /** * Enqueue locally stored site fragment assets. * * @return void */ function libresign_theme_site_fragment_enqueue_assets() { - if ( is_admin() ) { + if ( is_admin() || libresign_theme_site_fragment_is_excluded_page() ) { return; } @@ -488,7 +495,7 @@ function libresign_theme_render_site_fragment( $fragment_type ) { */ function libresign_theme_replace_site_fragment_template_part( $block_content, $block ) { $slug = isset( $block['attrs']['slug'] ) ? (string) $block['attrs']['slug'] : ''; - if ( ! in_array( $slug, libresign_theme_site_fragment_supported_types(), true ) ) { + if ( ! in_array( $slug, libresign_theme_site_fragment_supported_types(), true ) || libresign_theme_site_fragment_is_excluded_page() ) { return $block_content; } diff --git a/tests/Integration/Inc/FooterFragmentTest.php b/tests/Integration/Inc/FooterFragmentTest.php index c2b1d41..125f9f1 100644 --- a/tests/Integration/Inc/FooterFragmentTest.php +++ b/tests/Integration/Inc/FooterFragmentTest.php @@ -17,6 +17,8 @@ public function set_up() { } public function tear_down() { + $_SERVER['REQUEST_URI'] = ''; + foreach ( array( 'header', 'footer' ) as $fragment_type ) { libresign_theme_site_fragment_recursive_delete( libresign_theme_site_fragment_storage_base_dir( $fragment_type ) ); } @@ -211,6 +213,39 @@ public function test_renders_and_enqueues_the_stored_fragments_in_place_of_the_t $this->assertSame( 'module', wp_scripts()->get_data( 'libresign-site-header-fragment', 'type' ) ); } + /** + * @dataProvider provide_pages_without_the_site_fragments + */ + public function test_keeps_the_theme_header_and_footer_on_a_page_with_account_or_payment_data( $page ) { + $this->store( + array( + array( 'header', 'default', '
stored
' ), + array( 'footer', 'default', '
stored
' ), + ) + ); + $page(); + wp_dequeue_style( 'libresign-site-header-fragment' ); + wp_dequeue_script( 'libresign-site-footer-fragment' ); + + do_action( 'wp_enqueue_scripts' ); + + $this->assertSame( '
theme
', apply_filters( 'render_block_core/template-part', '
theme
', array( 'attrs' => array( 'slug' => 'header' ) ) ) ); + $this->assertSame( '
theme
', apply_filters( 'render_block_core/template-part', '', array( 'attrs' => array( 'slug' => 'footer' ) ) ) ); + $this->assertFalse( wp_style_is( 'libresign-site-header-fragment' ) ); + $this->assertFalse( wp_script_is( 'libresign-site-footer-fragment' ) ); + } + + public static function provide_pages_without_the_site_fragments() { + yield 'the checkout' => array( static fn () => add_filter( 'woocommerce_is_checkout', '__return_true' ) ); + yield 'the order received page' => array( static fn () => add_filter( 'woocommerce_is_order_received_page', '__return_true' ) ); + yield 'my account and login' => array( static fn () => add_filter( 'woocommerce_is_account_page', '__return_true' ) ); + yield 'the lost password route' => array( + static function () { + $_SERVER['REQUEST_URI'] = '/lost-password/'; + }, + ); + } + private function store( $fragments ) { $artifacts = array();