Skip to content

Commit

Permalink
Fix inline style bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndiego committed May 9, 2022
1 parent 4ec8b33 commit 9024b5a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions includes/frontend/visibility-tests/screen-size.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ function screen_size_test( $is_visible, $settings, $controls ) {
// Register an alias screen-size styles file. This is needed for wp_add_inline_style.
wp_register_style( 'block-visibility-screen-size-styles', false, array(), '1.0.0' );
wp_enqueue_style( 'block-visibility-screen-size-styles' );

$styles = get_screen_size_styles( $settings );

if ( $styles ) {
wp_add_inline_style( 'block-visibility-screen-size-styles', $styles );
}
}

// Always return true because the screen size controls are handled with CSS.
Expand Down Expand Up @@ -127,6 +121,23 @@ function add_screen_size_classes( $custom_classes, $settings, $controls ) {
}
add_filter( 'block_visibility_control_set_add_custom_classes', __NAMESPACE__ . '\add_screen_size_classes', 10, 3 );

/**
* Only add inline styles if a block with Screen Size controls is present.
*
* @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 );

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

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

0 comments on commit 9024b5a

Please sign in to comment.