Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions inc/footer-fragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/Integration/Inc/FooterFragmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
Expand Down Expand Up @@ -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', '<header>stored</header>' ),
array( 'footer', 'default', '<footer>stored</footer>' ),
)
);
$page();
wp_dequeue_style( 'libresign-site-header-fragment' );
wp_dequeue_script( 'libresign-site-footer-fragment' );

do_action( 'wp_enqueue_scripts' );

$this->assertSame( '<header>theme</header>', apply_filters( 'render_block_core/template-part', '<header>theme</header>', array( 'attrs' => array( 'slug' => 'header' ) ) ) );
$this->assertSame( '<footer>theme</footer>', apply_filters( 'render_block_core/template-part', '<footer>theme</footer>', 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();

Expand Down
Loading