Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent CSS from loading on unrelated pages #255

Merged
merged 1 commit into from
Sep 19, 2023
Merged
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
16 changes: 16 additions & 0 deletions settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

add_action( 'plugins_loaded', __NAMESPACE__ . '\replace_core_ui_with_custom' ); // Must run after Two Factor plugin loaded.
add_action( 'init', __NAMESPACE__ . '\register_block' );
add_action( 'enqueue_block_assets', __NAMESPACE__ . '\maybe_dequeue_stylesheet', 40 );

/**
* Registers the block
Expand Down Expand Up @@ -145,3 +146,18 @@ function login_footer_revalidate_customizations() {
</script>
<?php
}

/**
* Only load CSS when the block is actually used.
*
* Without this, the CSS will be loaded on every page, but it's only needed on the Account page.
*
* @todo this may not be necessary once https://github.com/WordPress/gutenberg/issues/54491 is resolved.
*/
function maybe_dequeue_stylesheet() {
if ( bbp_get_displayed_user_id() ) {
return;
}

wp_dequeue_style( 'wporg-two-factor-settings-style' );
}
Loading