Skip to content

Commit

Permalink
Fix inline styles bug in classic themes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndiego committed May 9, 2022
1 parent 7c961c3 commit 04e557f
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions includes/frontend/visibility-tests/screen-size.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,30 @@ function add_screen_size_classes( $custom_classes, $settings, $controls ) {
* @since 2.4.1
*/
function add_inline_styles() {
if ( wp_style_is( 'block-visibility-screen-size-styles' ) ) {

// Get the plugin core settings.
$settings = get_option( 'block_visibility_settings' );
$styles = get_screen_size_styles( $settings );
// Get the plugin core settings.
$settings = get_option( 'block_visibility_settings' );

// We do not want to have to do this, but needed for classic themes. This
// will enqueue the screen size inline styles on all pages, but does fix
// the multiple printing of styles issue.
// @TODO explore alternative approaches.
if (
is_control_enabled( $settings, 'screen_size' ) &&
is_control_enabled( $settings, 'screen_size', 'enable_frontend_css' ) &&
! wp_script_is( 'block-visibility-screen-size-styles' )
) {
wp_register_style( 'block-visibility-screen-size-styles', false, array(), '1.0.0' );
wp_enqueue_style( 'block-visibility-screen-size-styles' );
}

if ( wp_style_is( 'block-visibility-screen-size-styles' ) ) {
$styles = get_screen_size_styles( $settings );

wp_add_inline_style( 'block-visibility-screen-size-styles', $styles );
}
}
add_filter( 'wp_enqueue_scripts', __NAMESPACE__ . '\add_inline_styles' );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\add_inline_styles', 1000 );

/**
* Get the screen size styles.
Expand Down

0 comments on commit 04e557f

Please sign in to comment.